當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandStack類代碼示例

本文整理匯總了Java中org.eclipse.emf.common.command.CommandStack的典型用法代碼示例。如果您正苦於以下問題:Java CommandStack類的具體用法?Java CommandStack怎麽用?Java CommandStack使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommandStack類屬於org.eclipse.emf.common.command包,在下文中一共展示了CommandStack類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public static Object execute(TransactionalEditingDomain editingDomain, RecordingCommand command) {
	final CommandStack commandStack = editingDomain.getCommandStack();
	ResourceSet rs = editingDomain.getResourceSet();
	IExecutionCheckpoint checkpoint = IExecutionCheckpoint.CHECKPOINTS.get(rs);
	Object result = null;
	try {
		if (checkpoint != null) {
			checkpoint.allow(rs, true);
		}
		commandStack.execute(command);
		if (command.getResult() != null && command.getResult().size() == 1) {
			result = command.getResult().iterator().next();
		}
	} finally {
		if (checkpoint != null) {
			checkpoint.allow(rs, false);
		}
	}
	return result;
}
 
開發者ID:eclipse,項目名稱:gemoc-studio-modeldebugging,代碼行數:21,代碼來源:CommandExecution.java

示例2: commandStackChanged

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public void commandStackChanged(final EventObject event) {
    getContainer().getDisplay().asyncExec(new Runnable() {
        public void run() {
            firePropertyChange(IEditorPart.PROP_DIRTY);

            // Try to select the affected objects.
            //
            Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
            if (mostRecentCommand != null) {
                setSelectionToViewer(mostRecentCommand.getAffectedObjects());
            }
            for (Iterator<PropertySheetPage> i = propertySheetPages.iterator(); i.hasNext();) {
                PropertySheetPage propertySheetPage = i.next();
                if (propertySheetPage.getControl().isDisposed()) {
                    i.remove();
                } else {
                    propertySheetPage.refresh();
                }
            }
        }
    });
}
 
開發者ID:ObeoNetwork,項目名稱:M2Doc,代碼行數:23,代碼來源:GenconfEditor.java

示例3: createCommandStack

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
protected CommandStack createCommandStack() {
    CommandStack result = createNiceMock(CommandStack.class);
    reset(result);

    result.execute(isA(Command.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            Object[] args = getCurrentArguments();
            assert args.length == 1;
            assert args[0] instanceof Command;

            Command cmd = (Command) args[0];
            if (cmd instanceof RecordingCommand) {
                RecordingCommand rc = (RecordingCommand) cmd;
                rc.execute();
            }

            return cmd;
        }
    }).anyTimes();
    replay(result);
    return result;
}
 
開發者ID:vitruv-tools,項目名稱:Vitruv,代碼行數:26,代碼來源:MockEditingDomainFactory.java

示例4: createEmfFileForDiagram

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public static void createEmfFileForDiagram(URI diagramResourceUri, final Diagram diagram) {

    // Create a resource set and EditingDomain
    final TransactionalEditingDomain editingDomain = GraphitiUiInternal.getEmfService().createResourceSetAndEditingDomain();
    final ResourceSet resourceSet = editingDomain.getResourceSet();
    // Create a resource for this file.
    final Resource resource = resourceSet.createResource(diagramResourceUri);
    final CommandStack commandStack = editingDomain.getCommandStack();
    commandStack.execute(new RecordingCommand(editingDomain) {

      @Override
      protected void doExecute() {
        resource.setTrackingModification(true);
        resource.getContents().add(diagram);

      }
    });

    save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
    editingDomain.dispose();
  }
 
開發者ID:eclipse,項目名稱:triquetrum,代碼行數:22,代碼來源:FileService.java

示例5: mergeBack

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
protected EObject mergeBack(final EObject object, final TransactionalEditingDomain editingDomain) {
  XtextResource _resource = this.resourceProvider.getResource();
  IParseResult _parseResult = _resource.getParseResult();
  final EObject modelCopy = _parseResult.getRootASTElement();
  final EObject copy = this.modelMerger.findMatchingObject(modelCopy, object);
  boolean _or = false;
  if ((copy == null)) {
    _or = true;
  } else {
    EObject _eContainer = copy.eContainer();
    boolean _tripleEquals = (_eContainer == null);
    _or = _tripleEquals;
  }
  if (_or) {
    return null;
  }
  CommandStack _commandStack = editingDomain.getCommandStack();
  _commandStack.execute(new RecordingCommand(editingDomain, "Text Changes") {
    @Override
    protected void doExecute() {
      TextPropertiesViewPart.this.modelMerger.merge(copy, object);
    }
  });
  return copy;
}
 
開發者ID:spoenemann,項目名稱:xtext-gef,代碼行數:26,代碼來源:TextPropertiesViewPart.java

示例6: refreshRepresentations

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
/**
 * Refreshes given {@link DRepresentation} in the given {@link TransactionalEditingDomain}.
 * 
 * @param transactionalEditingDomain
 *            the {@link TransactionalEditingDomain}
 * @param representations
 *            the {@link List} of {@link DRepresentation} to refresh
 */
public void refreshRepresentations(final TransactionalEditingDomain transactionalEditingDomain,
		final List<DRepresentation> representations) {
	// TODO prevent the editors from getting dirty
	if (representations.size() != 0) {
		final RefreshRepresentationsCommand refresh = new RefreshRepresentationsCommand(
				transactionalEditingDomain, new NullProgressMonitor(), representations);

		CommandStack commandStack = transactionalEditingDomain.getCommandStack();

		// If the command stack is transactionnal, we add a one-shot exception handler.
		if (commandStack instanceof AbstractTransactionalCommandStack) {
			AbstractTransactionalCommandStack transactionnalCommandStack = (AbstractTransactionalCommandStack)commandStack;
			transactionnalCommandStack.setExceptionHandler(new ExceptionHandler() {

				@Override
				public void handleException(Exception e) {
					// TODO Auto-generated method stub

					String repString = representations.stream().map(r -> r.getName()).collect(
							Collectors.joining(", "));
					DebugSiriusIdeUiPlugin.getPlugin().getLog().log(new Status(IStatus.WARNING,
							DebugSiriusIdeUiPlugin.ID, "Failed to refresh Sirius representation(s)["
									+ repString + "], we hope to be able to do it later", e));

					// Self-remove from the command stack.
					transactionnalCommandStack.setExceptionHandler(null);

				}
			});
		}

		commandStack.execute(refresh);

	}
}
 
開發者ID:eclipse,項目名稱:gemoc-studio-modeldebugging,代碼行數:44,代碼來源:AbstractDSLDebuggerServices.java

示例7: createEditingDomain

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public TransactionalEditingDomain createEditingDomain(URL modelURL) {
    TransactionalEditingDomain result = createNiceMock(InternalTransactionalEditingDomain.class);
    ResourceSet editorRS = createResourceSet(modelURL);
    CommandStack commandStack = createCommandStack();
    EObject root = editorRS.getResources().get(0).getContents().get(0);

    reset(result);
    expect(result.getResourceSet()).andReturn(editorRS).anyTimes();
    expect(result.getRoot(isA(EObject.class))).andReturn(root).anyTimes();
    expect(result.getCommandStack()).andReturn(commandStack).anyTimes();

    replay(result);
    return result;
}
 
開發者ID:vitruv-tools,項目名稱:Vitruv,代碼行數:15,代碼來源:MockEditingDomainFactory.java

示例8: createDiagram

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
/**
 * Create a diagram with given URIs.
 * 
 * @param diagramURI
 *            URI for the diagram file
 * @param modelURI
 *            URI for the model file
 * @param progressMonitor
 *            progress monitor
 * @return a resource for the new diagram file
 */
private Resource createDiagram(final URI diagramURI, final URI modelURI,
        final IProgressMonitor progressMonitor) {
    progressMonitor.beginTask("Creating diagram and model files", 2);
    // create a resource set and editing domain
    TransactionalEditingDomain editingDomain = GraphitiUi.getEmfService()
            .createResourceSetAndEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    CommandStack commandStack = editingDomain.getCommandStack();
    // create resources for the diagram and domain model files
    final Resource diagramResource = resourceSet.createResource(diagramURI);
    final Resource modelResource = resourceSet.createResource(modelURI);
    if (diagramResource != null && modelResource != null) {
        commandStack.execute(new RecordingCommand(editingDomain) {
            @Override
            protected void doExecute() {
                createModel(diagramResource, diagramURI.lastSegment(), modelResource,
                        modelURI.lastSegment());
            }
        });
        progressMonitor.worked(1);

        try {
            modelResource.save(createSaveOptions());
            diagramResource.save(createSaveOptions());
        } catch (IOException exception) {
            IStatus status = new Status(IStatus.ERROR, PLUGIN_ID,
                    "Unable to store model and diagram resources", exception);
            StatusManager.getManager().handle(status);
        }
        setCharset(WorkspaceSynchronizer.getFile(modelResource));
        setCharset(WorkspaceSynchronizer.getFile(diagramResource));
    }
    progressMonitor.done();
    return diagramResource;
}
 
開發者ID:spoenemann,項目名稱:xtext-gef,代碼行數:47,代碼來源:GraphitiNewWizard.java

示例9: initializeEditingDomain

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
protected void initializeEditingDomain(AdapterFactoryEditingDomain editingDomain) {

		this.editingDomain = editingDomain;
		this.adapterFactory = editingDomain.getAdapterFactory();

		refreshListener = new CommandStackListener() {
			public void commandStackChanged(final EventObject event) {
				getContainer().getDisplay().asyncExec(new Runnable() {
					public void run() {
						firePropertyChange(IEditorPart.PROP_DIRTY);

						// Try to select the affected objects.
						//
						Command mostRecentCommand = ((CommandStack) event.getSource()).getMostRecentCommand();
						if (mostRecentCommand != null) {
							setSelectionToViewer(mostRecentCommand.getAffectedObjects());
						}
						for (Iterator<PropertySheetPage> i = propertySheetPages.iterator(); i.hasNext();) {
							PropertySheetPage propertySheetPage = i.next();
							if (propertySheetPage.getControl().isDisposed()) {
								i.remove();
							} else {
								propertySheetPage.refresh();
							}
						}
					}
				});
			}
		};

		commandStack = editingDomain.getCommandStack();
		commandStack.addCommandStackListener(refreshListener);

	}
 
開發者ID:mondo-project,項目名稱:mondo-demo-wt,代碼行數:35,代碼來源:WTSpec4MEditor.java

示例10: createEmfFileForDiagram

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public static TransactionalEditingDomain createEmfFileForDiagram(URI diagramResourceUri, final Diagram diagram,
		final InputStream contentStream, final IFile resourceFile) {

	// Create a resource set and EditingDomain
	final TransactionalEditingDomain editingDomain = DiagramEditorFactory.createResourceSetAndEditingDomain();
	final ResourceSet resourceSet = editingDomain.getResourceSet();
	// Create a resource for this file.
	final Resource resource = resourceSet.createResource(diagramResourceUri);

	final CommandStack commandStack = editingDomain.getCommandStack();
	commandStack.execute(new RecordingCommand(editingDomain) {

		@Override
		protected void doExecute() {
			resource.setTrackingModification(true);
			if (contentStream == null) {
				resource.getContents().add(diagram);
			} else {
				try {
					resourceFile.create(contentStream, IResource.FORCE, null);
				} catch (CoreException e) {
					// TODO
					e.printStackTrace();
				}
			}
		}
	});

	save(editingDomain, Collections.<Resource, Map<?, ?>> emptyMap());
	return editingDomain;
}
 
開發者ID:logicalhacking,項目名稱:SecureBPMN,代碼行數:32,代碼來源:FileService.java

示例11: deleteCommandTest

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
/**
 * check element deletion tracking.
 * 
 * @throws UnsupportedOperationException on test fail
 * @throws UnsupportedNotificationException on test fail
 */
@Test
public void deleteCommandTest() throws UnsupportedOperationException, UnsupportedNotificationException {

	final TestElement useCase = Create.testElement();
	Add.toProject(getLocalProject(), useCase);
	clearOperations();
	final ModelElementId useCaseId = getProject().getModelElementId(useCase);

	final Command deleteCommand = DeleteCommand.create(
		ESWorkspaceProviderImpl.getInstance().getEditingDomain(),
		useCase);
	final CommandStack commandStack = ESWorkspaceProviderImpl.getInstance().getEditingDomain().getCommandStack();
	if (deleteCommand.canExecute()) {
		commandStack.execute(deleteCommand);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}

	final List<AbstractOperation> operations = getProjectSpace().getOperations();

	assertEquals(1, operations.size());
	final AbstractOperation operation = operations.get(0);
	assertTrue(operation instanceof CreateDeleteOperation);
	final CreateDeleteOperation createDeleteOperation = (CreateDeleteOperation) operation;

	assertEquals(useCaseId, createDeleteOperation.getModelElementId());
	assertEquals(0, createDeleteOperation.getSubOperations().size());
	assertTrue(createDeleteOperation.isDelete());
}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:36,代碼來源:CommandTest.java

示例12: createDiagram

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
public static Resource createDiagram(final URI diagramURI, final URI modelURI) {
    // create a resource set and editing domain
    TransactionalEditingDomain editingDomain = GraphitiUi.getEmfService()
            .createResourceSetAndEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    CommandStack commandStack = editingDomain.getCommandStack();
    // create resources for the diagram and domain model files
    final Resource diagramResource = resourceSet.createResource(diagramURI);
    final Resource modelResource = resourceSet.createResource(modelURI);
    if (diagramResource != null && modelResource != null) {
        commandStack.execute(new RecordingCommand(editingDomain) {
            @Override
            protected void doExecute() {
                createModel(diagramResource, diagramURI.lastSegment(), modelResource,
                        modelURI.lastSegment());
            }
        });

        try {
            modelResource.save(createSaveOptions());
            diagramResource.save(createSaveOptions());
        } catch (IOException exception) {
            IStatus status = new Status(IStatus.ERROR, "de.cau.cs.rtprak.turing.graphiti",
                    "Unable to store model and diagram resources", exception);
            StatusManager.getManager().handle(status);
        }
        setCharset(WorkspaceSynchronizer.getFile(modelResource));
        setCharset(WorkspaceSynchronizer.getFile(diagramResource));
    }
    return diagramResource;
}
 
開發者ID:CloudScale-Project,項目名稱:Environment,代碼行數:32,代碼來源:Util.java

示例13: createDiagram

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
/**
 * Create a diagram with given URIs.
 * 
 * @param diagramURI
 *            URI for the diagram file
 * @param modelURI
 *            URI for the model file
 * @param progressMonitor
 *            progress monitor
 * @return a resource for the new diagram file
 */
private Resource createDiagram(final URI diagramURI, final URI modelURI,
        final IProgressMonitor progressMonitor) {
    progressMonitor.beginTask("Creating diagram and model files", 2);
    // create a resource set and editing domain
    TransactionalEditingDomain editingDomain = GraphitiUi.getEmfService()
            .createResourceSetAndEditingDomain();
    ResourceSet resourceSet = editingDomain.getResourceSet();
    CommandStack commandStack = editingDomain.getCommandStack();
    // create resources for the diagram and domain model files
    final Resource diagramResource = resourceSet.createResource(diagramURI);
    final Resource modelResource = resourceSet.createResource(modelURI);
    if (diagramResource != null && modelResource != null) {
        commandStack.execute(new RecordingCommand(editingDomain) {
            @Override
            protected void doExecute() {
                createModel(diagramResource, diagramURI.lastSegment(), modelResource,
                        modelURI.lastSegment());
            }
        });
        progressMonitor.worked(1);

        try {
            modelResource.save(createSaveOptions());
            diagramResource.save(createSaveOptions());
        } catch (IOException exception) {
            IStatus status = new Status(IStatus.ERROR, "de.cau.cs.rtprak.turing.graphiti",
                    "Unable to store model and diagram resources", exception);
            StatusManager.getManager().handle(status);
        }
        setCharset(WorkspaceSynchronizer.getFile(modelResource));
        setCharset(WorkspaceSynchronizer.getFile(diagramResource));
    }
    progressMonitor.done();
    return diagramResource;
}
 
開發者ID:CloudScale-Project,項目名稱:Environment,代碼行數:47,代碼來源:GraphitiNewWizard.java

示例14: handleRename

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
private void handleRename(final String theNewName, final EObject theSemanticElement,
        final TransactionalEditingDomain theDomain, final CommandStack theCommandStack) {
    final SetName setName = theCommandStack instanceof IWorkspaceCommandStack
            && theLastOperationCreatedTheElement(theSemanticElement, (IWorkspaceCommandStack) theCommandStack) ? new SetNameTheFirstTime(
                    theDomain, theNewName, theSemanticElement, (IWorkspaceCommandStack) theCommandStack) : new Rename(
                            theDomain, theNewName, theSemanticElement, graphicalEditPart.getViewer().getControl().getShell());
                    if (setName.confirm()) {
                        theCommandStack.execute(setName);
                        setName.after();
                    }
}
 
開發者ID:info-sharing-environment,項目名稱:NIEM-Modeling-Tool,代碼行數:12,代碼來源:ClassifierNamePopupEditorConfiguration.java

示例15: handleCancelation

import org.eclipse.emf.common.command.CommandStack; //導入依賴的package包/類
private void handleCancelation(final EObject theSemanticElement, final TransactionalEditingDomain theDomain,
        final CommandStack theCommandStack) {
    final IWorkspaceCommandStack theWorkspaceCommandStack = (IWorkspaceCommandStack) theCommandStack;
    if (theLastOperationCreatedTheElement(theSemanticElement, theWorkspaceCommandStack)) {
        theCommandStack.undo();
        final IOperationHistory theOperationHistory = theWorkspaceCommandStack.getOperationHistory();
        theOperationHistory.dispose(theWorkspaceCommandStack.getDefaultUndoContext(), false, true, false);
    }
}
 
開發者ID:info-sharing-environment,項目名稱:NIEM-Modeling-Tool,代碼行數:10,代碼來源:ClassifierNamePopupEditorConfiguration.java


注:本文中的org.eclipse.emf.common.command.CommandStack類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。