Java 类org.eclipse.core.commands.operations.ObjectUndoContext 实例源码

项目:che    文件:RefactoringCorePlugin.java   
public void stop(BundleContext context) throws Exception {
  if (fRefactoringUndoContext != null) {
    IUndoContext workspaceContext =
        (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
    if (workspaceContext instanceof ObjectUndoContext) {
      ((ObjectUndoContext) workspaceContext).removeMatch(fRefactoringUndoContext);
    }
  }
  if (fgUndoManager != null) fgUndoManager.shutdown();
  final RefactoringHistoryService service = RefactoringHistoryService.getInstance();
  service.disconnect();
  if (fRefactoringHistoryListener != null)
    service.removeHistoryListener(fRefactoringHistoryListener);
  RefactoringContributionManager.getInstance().disconnect();
  super.stop(context);
}
项目:OpenSPIFe    文件:ChartEditor.java   
/**
 * @throws PartInitException
 */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    listener = new EditorPartInputActivationListener(this);
    IFile file = CommonUtils.getAdapter(input, IFile.class);
    IProject project = file.getProject();
    synchronizer = new ProjectResourceSetSynchronizer(project, gov.nasa.ensemble.emf.transaction.TransactionUtils.createTransactionResourceSet());
    ResourceSet resourceSet = synchronizer.getResourceSet();
    resourceSet.setURIConverter(new ProjectURIConverter(project));
    resourceSet.getPackageRegistry().put(ChartPackage.eNS_URI, ChartPackage.eINSTANCE);
    profileSynchronizer = ProfileSynchronizer.createInstance(project, resourceSet);
    editingDomain = gov.nasa.ensemble.emf.transaction.TransactionUtils.getDomain(resourceSet);
    undoContext = new ObjectUndoContext(getEditingDomain());
    site.setSelectionProvider(new EnsembleSelectionProvider(this.toString()));
    UndoRedoUtils.setupUndoRedo(site.getActionBars(), site, undoContext);
    createModel(input);
    editingDomain.addResourceSetListener(pageExtentListener);
}
项目:che    文件:RefactoringCorePlugin.java   
public static IUndoContext getUndoContext() {
  if (fRefactoringUndoContext == null) {
    fRefactoringUndoContext = new RefactoringUndoContext();
    IUndoContext workspaceContext =
        (IUndoContext) ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
    if (workspaceContext instanceof ObjectUndoContext) {
      ((ObjectUndoContext) workspaceContext).addMatch(fRefactoringUndoContext);
    }
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    operationHistory.setLimit(fRefactoringUndoContext, 5);
  }
  return fRefactoringUndoContext;
}
项目:OpenSPIFe    文件:ProfileDataPointsEditor.java   
public ProfileDataPointsEditor(Composite parent, DetailProviderParameter parameter) {
    EObject target = parameter.getTarget();
    if (!(target instanceof Profile)) {
        throw new IllegalArgumentException("ProfileDataPointEditor target must be a Profile.");
    }
    Profile profile = (Profile) target;
    IItemPropertyDescriptor pd = parameter.getPropertyDescriptor();
    FormToolkit toolkit = parameter.getDetailFormToolkit();

    String displayName = EMFDetailUtils.getDisplayName(profile, pd);
    Section section = DetailFormToolkit.createSection(toolkit, parent, displayName, null, false);
    Composite sectionComposite = toolkit.createComposite(section);
    sectionComposite.setLayout(new GridLayout(2, false));
    section.setClient(sectionComposite);

    String editabilityText = (isProfileEditable(profile) ? EDITABLE_MESSAGE : READ_ONLY_MESSAGE);
    Label editabilityLabel = toolkit.createLabel(sectionComposite, editabilityText);
    editabilityLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1));

    final TreeTableViewer viewer = createTreeTableViewer(sectionComposite, toolkit, profile);
    EditingDomain domain = EMFUtils.getAnyDomain(profile);
    IUndoContext undoContext = new ObjectUndoContext(domain);
    ProfileEditorModel editorModel = new ProfileEditorModel(isProfileEditable(profile), undoContext);
    viewer.setEditorModel(editorModel);
    viewer.setInput(profile);
    parent.layout(true);
}
项目:OpenSPIFe    文件:PlanReadOnlyOperationApprover.java   
protected IStatus checkReadOnly(IUndoableOperation operation) {
    for (IUndoContext context : operation.getContexts()) {
        if (context instanceof ObjectUndoContext) {
            ObjectUndoContext objectUndoContext = (ObjectUndoContext) context;
            if (objectUndoContext.getObject() instanceof EditingDomain) {
                EditingDomain domain = (EditingDomain) objectUndoContext.getObject();
                ResourceSet resourceSet = domain.getResourceSet();
                List<Resource> resources = new ArrayList<Resource>(resourceSet.getResources());
                for (Resource resource : resources) {
                    if (resource instanceof PlanResourceImpl) {
                        for (EObject content : resource.getContents()) {
                            if (content instanceof EPlan && !EPlanUtils.isTemplatePlan(content)) {
                                EPlan plan = (EPlan) content;
                                if (domain.isReadOnly(resource)
                                    || (!registry.canModify(plan) 
                                            && !registry.canModifyStructure(plan))) {
                                    Throwable exception = new IllegalStateException("checkReadOnly failed: " + operation);
                                    LogUtil.error(exception);
                                    return new Status(IStatus.ERROR, "gov.nasa.ensemble.core.plan.editor", 7, "plan is read only", exception); 
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return Status.OK_STATUS;
}
项目:translationstudio8    文件:XLIFFEditorImplWithNatTable.java   
private void initializeOperationHistory() {
    // create a unique undo context to
    // represent this view's undo history
    undoContext = new ObjectUndoContext(this);

    // set the undo limit for this context based on the preference
    HISTORY.setLimit(undoContext, 99);

    // 初始化“重做、”“撤销”菜单项
    undoRedoGroup = new UndoRedoActionGroup(getSite(), undoContext, true);
}
项目:tmxeditor8    文件:XLIFFEditorImplWithNatTable.java   
private void initializeOperationHistory() {
    // create a unique undo context to
    // represent this view's undo history
    undoContext = new ObjectUndoContext(this);

    // set the undo limit for this context based on the preference
    HISTORY.setLimit(undoContext, 99);

    // 初始化“重做、”“撤销”菜单项
    undoRedoGroup = new UndoRedoActionGroup(getSite(), undoContext, true);
}
项目:birt    文件:JSEditor.java   
/**
 * Returns current undo level.
 * 
 * @return current undo level.
 */
private int getUndoLevel( )
{
    SourceViewer viewer = getViewer( );
    IUndoableOperation[] history = viewer == null ? null
            : OperationHistoryFactory.getOperationHistory( )
                    .getUndoHistory( new ObjectUndoContext( viewer.getDocument( ) ) );

    return history == null ? -1 : history.length;
}
项目:OpenSPIFe    文件:EMFUtils.java   
public static IUndoContext getUndoContext(EditingDomain domain) {
    if (domain != null) {
        return new ObjectUndoContext(domain);
    }
    return IOperationHistory.GLOBAL_UNDO_CONTEXT;
}
项目:OpenSPIFe    文件:ValueDropEditPolicy.java   
@Override
public Command getCommand(Request request) {
    if (understandsRequest(request)) {
        ChangeBoundsRequest cbr = (ChangeBoundsRequest)request;
        Point location = cbr.getLocation();
        EditPart targetEditPart = getViewer().findObjectAtExcluding(location, Collections.emptyList(), new TreeTimelineDataRowConditional());
        if (targetEditPart != null) {
            Object model = targetEditPart.getModel();
            Set<EPlanElement> elements = new HashSet<EPlanElement>();
            for (Object object : ((ChangeBoundsRequest)request).getEditParts()) {
                EPlanElement pe = null;
                if (object instanceof EPlanElement) {
                    pe = (EPlanElement) object;
                } else if (((EditPart)object).getModel() instanceof EPlanElement) {
                    pe = (EPlanElement) ((EditPart)object).getModel();
                }
                if (pe != null) {
                    elements.add(pe);
                }
            }
            if (!elements.isEmpty()) {
                EditingDomain domain = EMFUtils.getAnyDomain(getTimeline().getTimelineModel());
                if (domain != null) {
                    org.eclipse.emf.common.command.Command command = null;
                    if (REQ_CHANGE_VALUE_VIA_DROP.equals(request.getType())) {
                        command = SetCommand.create(domain, model, null, elements);
                    } else if (REQ_ADD_VALUE_VIA_DROP.equals(request.getType())) {
                        command = AddCommand.create(domain, model, null, elements);
                    }
                    if (command != null) {
                        IUndoContext undoContext = EMFUtils.getUndoContext(domain);
                        CommandUndoableOperation op = new CommandUndoableOperation(domain, command);
                        op.addContext(new ObjectUndoContext(domain));
                        return new OperationCommand(undoContext, op , getTimeline().getControl(), getViewer().getSite());
                    }
                }
            }
        }
    }
    return super.getCommand(request);
}
项目:OpenSPIFe    文件:UniqueMultiSelectSetOperation.java   
@Override
protected void execute() throws Throwable {
    List<EObject> targets = new ArrayList<EObject>();
    List<IItemPropertyDescriptor> pds = new ArrayList<IItemPropertyDescriptor>();
    EObject target = parameter.getTarget();
    if (target instanceof MultiEObject) {
        targets.addAll(((MultiEObject) target).getEObjects());
        pds.addAll(((MultiItemPropertyDescriptor) parameter.getPropertyDescriptor()).getPropertyDescriptors());
    } else {
        targets.add(target);
        pds.add(parameter.getPropertyDescriptor());
    }

    if (targets.isEmpty()) {
        return;
    }

    domain = AdapterFactoryEditingDomain.getEditingDomainFor(targets.get(0));
    ObjectUndoContext domainUndoContext = new ObjectUndoContext(domain);
    if (!hasContext(domainUndoContext)) {
        addContext(domainUndoContext);
    }

    compoundCommand = new CompoundCommand();
    for (int i = 0; i < pds.size(); i++) {
        IItemPropertyDescriptor pd = pds.get(i);
        EObject model = target = targets.get(i);
        EStructuralFeature feature = (EStructuralFeature) pd.getFeature(model);
        EObject commandOwner = EMFDetailUtils.getCommandOwner(pd, model);
        if (commandOwner != null) {
            model = commandOwner;
        }
        for (Object referencedObject : map.keySet()) {
            TriState triState = map.get(referencedObject);
            if (TriState.QUASI == triState) {
                continue;
            }
            boolean contained = ((Collection) model.eGet(feature)).contains(referencedObject);
            TriState originalTriState = originalMap.get(referencedObject);
            if (!CommonUtils.equals(triState, originalTriState)) {
                if (TriState.TRUE == triState && !contained) {
                    compoundCommand.append(AddCommand.create(domain, model, feature, referencedObject));
                } else if (TriState.FALSE == triState && contained) {
                    compoundCommand.append(RemoveCommand.create(domain, model, feature, referencedObject));
                }
            }
        }
    }
    if (!compoundCommand.isEmpty()) {
        gov.nasa.ensemble.emf.transaction.TransactionUtils.writing(domain, new Runnable() {
            @Override
            public void run() {
                compoundCommand.execute();
            }
        });
    }
}
项目:OpenSPIFe    文件:EMFTreeTableUtils.java   
public static TreeTableViewer<EObject, EAttribute> createEMFTreeTableViewer(Composite parent, EStructuralFeature structuralFeature, EClass eClass, EditingDomain editingDomain, boolean forceTreeParent, boolean useDefaultSortColumn, boolean isScrollable, boolean editable) {
    EPackage ePackage = eClass.getEPackage();
    EObject eObject = ePackage.getEFactoryInstance().create(eClass);
    AdapterFactory domainAdapterFactory = EMFUtils.getAdapterFactory(editingDomain);
    IItemPropertySource source = (IItemPropertySource) domainAdapterFactory.adapt(eObject, IItemPropertySource.class);

    List<ITreeTableColumn> columns = new ArrayList<ITreeTableColumn>();
    for (final IItemPropertyDescriptor descriptor : source.getPropertyDescriptors(eObject)) {
        if (!isVisible(descriptor.getFeature(eObject))) {
            continue;
        }
        DetailProviderParameter parameter = new DetailProviderParameter();
        parameter.setPropertyDescriptor(descriptor);
        parameter.setTarget(eObject);
        ITreeTableColumn column = null;
        IEMFTreeTableProvider provider = EMFUtils.adapt(eObject, IEMFTreeTableProvider.class);
        if (provider != null) {
            column = provider.getTreeTableColumn(parameter);
        }
        if (column == null) {
            String displayName = EMFDetailUtils.getDisplayName(eObject, descriptor);
            int columnWidth = getColumnWidth(eObject, descriptor);
            column = new ValidatedReferenceTreeTableColumn(parameter, displayName, columnWidth, editable);
        }
        columns.add(column);
    }

    TreeTableColumnConfiguration configuration = new TreeTableColumnConfiguration(columns.get(0), columns, (useDefaultSortColumn) ? columns.get(0) : null);
    TreeTableComposite composite = new TreeTableComposite(parent, configuration, useDefaultSortColumn, isScrollable);
    // this odd "if" preserves existing semantics that conflated sorting with layouts
    if (useDefaultSortColumn) {
        composite.setLayout(new FillLayout());
    } else {
        composite.setLayout(new TreeTableColumnLayout(true));
    }
    TreeTableViewer<EObject, EAttribute> viewer = new ReflowingTreeTableViewer<EObject, EAttribute>(composite, configuration, null);

    if(forceTreeParent) {
        viewer.getTree().setParent(parent);
    }

    AdapterFactory adapterFactory = EMFUtils.getAdapterFactory(editingDomain);
    viewer.setEditorModel(new IEnsembleEditorModel.STUB(new ObjectUndoContext(editingDomain)));
    viewer.setContentProvider(new EMFTreeTableContentProvider(adapterFactory, structuralFeature, eClass));
    viewer.setLabelProvider(new EMFTreeTableLabelProvider(adapterFactory));
    return viewer;      
}
项目:OpenSPIFe    文件:TestTemporalBoundColumn.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    undoContext = new ObjectUndoContext(this);

    START_ANYTIME_AFTER.getPoint().setEndpoint(Timepoint.START);
    START_ANYTIME_AFTER.setEarliest(TIME_A);
    START_ANYTIME_AFTER.setRationale("START_ANYTIME_AFTER");

    START_ANYTIME_BEFORE.getPoint().setEndpoint(Timepoint.START);
    START_ANYTIME_BEFORE.setLatest(TIME_A);
    START_ANYTIME_BEFORE.setRationale("START_ANYTIME_BEFORE");

    START_ANYTIME_BEFORE_ZERO_MIN.getPoint().setEndpoint(Timepoint.START);
    START_ANYTIME_BEFORE_ZERO_MIN.setEarliest(TIME_ZERO);
    START_ANYTIME_BEFORE_ZERO_MIN.setLatest(TIME_B);
    START_ANYTIME_BEFORE_ZERO_MIN.setRationale("START_ANYTIME_BEFORE_ZERO_MIN");

    START_ANYTIME_BETWEEN.getPoint().setEndpoint(Timepoint.START);
    START_ANYTIME_BETWEEN.setEarliest(TIME_A);
    START_ANYTIME_BETWEEN.setLatest(TIME_B);
    START_ANYTIME_BETWEEN.setRationale("START_ANYTIME_BETWEEN");

    START_EXACTLY_AT.getPoint().setEndpoint(Timepoint.START);
    START_EXACTLY_AT.setEarliest(TIME_A);
    START_EXACTLY_AT.setLatest(TIME_A);
    START_EXACTLY_AT.setRationale("START_EXACTLY_AT");

    END_ANYTIME_AFTER.getPoint().setEndpoint(Timepoint.END);
    END_ANYTIME_AFTER.setEarliest(TIME_B);
    END_ANYTIME_AFTER.setRationale("END_ANYTIME_AFTER");

    END_ANYTIME_BEFORE.getPoint().setEndpoint(Timepoint.END);
    END_ANYTIME_BEFORE.setLatest(TIME_B);
    END_ANYTIME_BEFORE.setRationale("END_ANYTIME_BEFORE");

    END_ANYTIME_BEFORE_ZERO_MIN.getPoint().setEndpoint(Timepoint.END);
    END_ANYTIME_BEFORE_ZERO_MIN.setEarliest(TIME_ZERO);
    END_ANYTIME_BEFORE_ZERO_MIN.setLatest(TIME_B);
    END_ANYTIME_BEFORE_ZERO_MIN.setRationale("END_ANYTIME_BEFORE_ZERO_MIN");

    END_EXACTLY_AT.getPoint().setEndpoint(Timepoint.END);
    END_EXACTLY_AT.setEarliest(TIME_A);
    END_EXACTLY_AT.setLatest(TIME_A);
    END_EXACTLY_AT.setRationale("END_EXACTLY_AT");

    END_ANYTIME_BETWEEN.getPoint().setEndpoint(Timepoint.END);
    END_ANYTIME_BETWEEN.setEarliest(TIME_A);
    END_ANYTIME_BETWEEN.setLatest(TIME_B);
    END_ANYTIME_BETWEEN.setRationale("END_ANYTIME_BETWEEN");
}