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


Java Command.canExecute方法代碼示例

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


在下文中一共展示了Command.canExecute方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: allocateIds

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Allocates ID's to recently pasted nodes.
 * 
 * @param nodes the recently pasted nodes
 * @param command the command responsible for adding the nodes
 */
private void allocateIds(final List<GNode> nodes, final CompoundCommand command) {

    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(graphEditor.getModel());
    final EAttribute feature = ModelPackage.Literals.GNODE__ID;

    for (final GNode node : nodes) {

        if (checkNeedsNewId(node, nodes)) {

            final String id = allocateNewId();
            final Command setCommand = SetCommand.create(domain, node, feature, id);

            if (setCommand.canExecute()) {
                command.appendAndExecute(setCommand);
            }

            graphEditor.getSkinLookup().lookupNode(node).initialize();
        }
    }
}
 
開發者ID:Heverton,項目名稱:grapheditor,代碼行數:27,代碼來源:TitledSkinController.java

示例2: allocateIds

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Allocates ID's to recently pasted nodes.
 * 
 * @param nodes the recently pasted nodes
 * @param command the command responsible for adding the nodes
 */
private void allocateIds(final List<GNode> nodes, final CompoundCommand command) {

    final EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(graphEditor.getModel());
    final EAttribute feature = GraphPackage.Literals.GNODE__ID;

    for (final GNode node : nodes) {

        if (checkNeedsNewId(node, nodes)) {

            final String id = allocateNewId();
            final Command setCommand = SetCommand.create(domain, node, feature, id);

            if (setCommand.canExecute()) {
                command.appendAndExecute(setCommand);
            }

            graphEditor.getSkinLookup().lookupNode(node).initialize();
        }
    }
}
 
開發者ID:tesis-dynaware,項目名稱:graph-editor,代碼行數:27,代碼來源:TitledSkinController.java

示例3: addNode

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Adds a node to the model.
 *
 * <p>
 * The node's x, y, width, and height values should be set before calling this method.
 * </p>
 *
 * @param model the {@link GModel} to which the node should be added
 * @param node the {@link GNode} to add to the model
 */
public static void addNode(final GModel model, final GNode node) {

    final EditingDomain editingDomain = getEditingDomain(model);

    if (editingDomain != null) {
        final Command command = AddCommand.create(editingDomain, model, NODES, node);

        if (command.canExecute()) {
            editingDomain.getCommandStack().execute(command);
        }
    }
}
 
開發者ID:Heverton,項目名稱:grapheditor,代碼行數:23,代碼來源:Commands.java

示例4: deleteCommandTest

import org.eclipse.emf.common.command.Command; //導入方法依賴的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

示例5: removeCommand_DirectCreation

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Tests remove command.
 */
@Test
public void removeCommand_DirectCreation() {

	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	new EMFStoreCommand() {
		@Override
		protected void doRun() {
			getProject().addModelElement(leafSection);
		}
	}.run(false);

	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// remove
	final Command removeCommand = RemoveCommand.create(editingDomain, leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, actor);
	if (removeCommand.canExecute()) {
		editingDomain.getCommandStack().execute(removeCommand);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}
	assertEquals(0, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canUndo());

	// undo the command
	editingDomain.getCommandStack().undo();
	assertEquals(1, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canRedo());

	// redo the command
	editingDomain.getCommandStack().redo();
	assertEquals(0, leafSection.getContainedElements().size());

}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:41,代碼來源:CommandTest.java

示例6: removeCommand

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Tests the remove command.
 */
@Test
public void removeCommand() {
	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	new EMFStoreCommand() {
		@Override
		protected void doRun() {
			getProject().addModelElement(leafSection);
		}
	}.run(false);

	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// remove
	final Collection<TestElement> toRemove = new ArrayList<TestElement>();
	toRemove.add(actor);
	final Command copyCommand = editingDomain.createCommand(RemoveCommand.class, new CommandParameter(leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, toRemove));
	if (copyCommand.canExecute()) {
		editingDomain.getCommandStack().execute(copyCommand);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}

	assertEquals(0, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canUndo());

	// undo the command
	editingDomain.getCommandStack().undo();
	assertEquals(1, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canRedo());

	// redo the command
	editingDomain.getCommandStack().redo();
	assertEquals(0, leafSection.getContainedElements().size());
}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:42,代碼來源:CommandTest.java

示例7: deleteCommand_DirectCreation

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Tests delete command.
 */
@Test
public void deleteCommand_DirectCreation() {

	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	Add.toProject(getLocalProject(), leafSection);

	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// delete
	final Collection<TestElement> toDelete = new ArrayList<TestElement>();
	toDelete.add(actor);
	final Command command = DeleteCommand.create(editingDomain, toDelete);
	if (command.canExecute()) {
		editingDomain.getCommandStack().execute(command);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}
	assertEquals(0, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canUndo());

	// undo the command
	editingDomain.getCommandStack().undo();
	assertEquals(1, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canRedo());

	// redo the command
	editingDomain.getCommandStack().redo();
	assertEquals(0, leafSection.getContainedElements().size());
}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:36,代碼來源:CommandTest.java

示例8: cutAndPasteFromClipboardCommand_DirectCreation

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Tests the cut to clipboard and paste from clipboard command.
 */
@Test
public void cutAndPasteFromClipboardCommand_DirectCreation() {

	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	new EMFStoreCommand() {
		@Override
		protected void doRun() {
			getProject().addModelElement(leafSection);
		}
	}.run(false);

	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// copy to clipboard
	final Command cutCommand = CutToClipboardCommand.create(editingDomain, leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, actor);

	if (cutCommand.canExecute()) {
		editingDomain.getCommandStack().execute(cutCommand);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}
	assertEquals(0, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canUndo());

	// undo the cut command
	editingDomain.getCommandStack().undo();
	assertEquals(1, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canRedo());

	// redo the cut command
	editingDomain.getCommandStack().redo();
	assertEquals(0, leafSection.getContainedElements().size());

	// paste from clipboard
	final Command pasteCommand = PasteFromClipboardCommand.create(editingDomain, leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS,
		CommandParameter.NO_INDEX);

	if (pasteCommand.canExecute()) {
		editingDomain.getCommandStack().execute(pasteCommand);
		assertEquals(1, leafSection.getContainedElements().size());
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}

	// undo the paste command
	editingDomain.getCommandStack().undo();
	assertEquals(0, leafSection.getContainedElements().size());

	// redo the paste command
	editingDomain.getCommandStack().redo();
	assertEquals(1, leafSection.getContainedElements().size());

}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:62,代碼來源:CommandTest.java

示例9: testFunnyIssue

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Might be no problem in runtime??!! Please have a look at it.
 */
@Test
public void testFunnyIssue() {

	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	new EMFStoreCommand() {
		@Override
		protected void doRun() {
			getProject().addModelElement(leafSection);
		}
	}.run(false);

	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// cut to clipboard
	final Command cutCommand = CutToClipboardCommand.create(editingDomain, leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS
		, actor);

	if (cutCommand.canExecute()) {
		editingDomain.getCommandStack().execute(cutCommand);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}
	assertEquals(0, leafSection.getContainedElements().size());
	assertTrue(editingDomain.getCommandStack().canUndo());

	// undo the command
	new EMFStoreCommand() {
		@Override
		protected void doRun() {
			editingDomain.getCommandStack().undo();
		}
	}.run(false);
	// does not work but is strange anyway
	// assertTrue(editingDomain.getCommandStack().canRedo());
	assertEquals(1, leafSection.getContainedElements().size());

}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:45,代碼來源:CommandTest.java

示例10: deleteCommand

import org.eclipse.emf.common.command.Command; //導入方法依賴的package包/類
/**
 * Tests the delete command.
 */
@Test
public void deleteCommand() {
	final TestElement leafSection = Create.testElement();
	final TestElement actor = Create.testElement();
	leafSection.getContainedElements().add(actor);

	Add.toProject(getLocalProject(), leafSection);

	clearOperations();

	assertEquals(0, getProjectSpace().getOperations().size());
	final EditingDomain editingDomain = ESWorkspaceProviderImpl.getInstance().getEditingDomain();

	// delete
	final Collection<TestElement> toDelete = new ArrayList<TestElement>();
	toDelete.add(actor);

	// delete actor from model elements feature
	final Command command = editingDomain.createCommand(DeleteCommand.class, new CommandParameter(leafSection,
		TestmodelPackage.Literals.TEST_ELEMENT__CONTAINED_ELEMENTS, toDelete));
	if (command.canExecute()) {
		editingDomain.getCommandStack().execute(command);
	} else {
		fail(COMMAND_NOT_EXECUTABLE);
	}

	assertEquals(0, leafSection.getContainedElements().size());
	// undo delete
	assertTrue(editingDomain.getCommandStack().canUndo());
	assertEquals(1, getProjectSpace().getOperations().size());

	// undo the command - add actor to model elements feature

	editingDomain.getCommandStack().undo();

	assertEquals(1, leafSection.getContainedElements().size());
	// // assertEquals(0, getProjectSpace().getOperations().size());
	assertTrue(editingDomain.getCommandStack().canRedo());

	// redo the command - delete again
	editingDomain.getCommandStack().redo();

	assertEquals(0, leafSection.getContainedElements().size());
}
 
開發者ID:edgarmueller,項目名稱:emfstore-rest,代碼行數:48,代碼來源:CommandTest.java


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