View | Details | Raw Unified | Return to bug 256496
Collapse All | Expand All

(-)src/org/eclipse/uml2/diagram/clazz/part/UMLCreateShortcutAction.java (-6 / +44 lines)
Lines 3-10 Link Here
3
import org.eclipse.core.commands.AbstractHandler;
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.core.commands.operations.IOperationHistory;
6
import org.eclipse.core.commands.operations.OperationHistoryFactory;
7
import org.eclipse.core.commands.operations.OperationHistoryFactory;
8
import org.eclipse.core.runtime.IStatus;
7
import org.eclipse.core.runtime.NullProgressMonitor;
9
import org.eclipse.core.runtime.NullProgressMonitor;
10
import org.eclipse.core.runtime.Status;
8
import org.eclipse.emf.common.util.URI;
11
import org.eclipse.emf.common.util.URI;
9
import org.eclipse.emf.common.util.WrappedException;
12
import org.eclipse.emf.common.util.WrappedException;
10
import org.eclipse.emf.ecore.EObject;
13
import org.eclipse.emf.ecore.EObject;
Lines 12-20 Link Here
12
import org.eclipse.gef.EditPart;
15
import org.eclipse.gef.EditPart;
13
import org.eclipse.gmf.runtime.common.core.command.ICommand;
16
import org.eclipse.gmf.runtime.common.core.command.ICommand;
14
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
17
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
20
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
15
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
21
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
16
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
22
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
17
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
23
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
24
import org.eclipse.gmf.runtime.notation.Diagram;
18
import org.eclipse.gmf.runtime.notation.Node;
25
import org.eclipse.gmf.runtime.notation.Node;
19
import org.eclipse.gmf.runtime.notation.View;
26
import org.eclipse.gmf.runtime.notation.View;
20
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
Lines 61-74 Link Here
61
		if (selectedElement == null) {
68
		if (selectedElement == null) {
62
			return null;
69
			return null;
63
		}
70
		}
64
		CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(new EObjectAdapter(selectedElement), Node.class, null, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
71
		
65
		ICommand command = new CreateCommand(editingDomain, viewDescriptor, view);
72
		IOperationHistory history = OperationHistoryFactory.getOperationHistory();
66
		command = command.compose(new UMLCreateShortcutDecorationsCommand(editingDomain, view, viewDescriptor));
73
		IStatus status = createShortcut(editingDomain, history, selectedElement, selectedDiagramPart, diagramEditor);
74
		
75
		if (!status.isOK()) {
76
			UMLDiagramEditorPlugin.getInstance().logError(status.getMessage(), status.getException());
77
		}
78
		
79
		return null;
80
	}
81
82
	public static IStatus createShortcut(
83
			TransactionalEditingDomain editingDomain,
84
			IOperationHistory history, 
85
			EObject selectedElement, EditPart editPart,
86
			IEditorPart diagramEditor) {
87
88
		final View view = (View) editPart.getModel();
89
		final EditPart parentPart = editPart.getParent();
90
		final Diagram diagram = view.getDiagram();
91
		
92
		CreateViewRequest.ViewDescriptor viewDescriptor = new CreateViewRequest.ViewDescriptor(
93
				new EObjectAdapter(selectedElement), Node.class, null, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
94
		
95
		ICommand command = new CreateCommand(editingDomain, viewDescriptor, diagram);
96
		command = command.compose(new UMLCreateShortcutDecorationsCommand(editingDomain, diagram, viewDescriptor));
97
		IStatus status = null;
67
		try {
98
		try {
68
			OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
99
			status = OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
69
		} catch (ExecutionException e) {
100
		} catch (ExecutionException e) {
70
			UMLDiagramEditorPlugin.getInstance().logError("Unable to create shortcut", e); //$NON-NLS-1$
101
			status = new Status(IStatus.ERROR, UMLDiagramEditorPlugin.ID, IStatus.OK, "Unable to create shortcut", e); //$NON-NLS-1$
71
		}
102
		}
72
		return null;
103
		
104
105
		CanonicalEditPolicy policy = (CanonicalEditPolicy) parentPart.getEditPolicy(EditPolicyRoles.CANONICAL_ROLE);
106
		if (policy != null) {
107
			policy.refresh();
108
		}
109
		
110
		return status;
73
	}
111
	}
74
}
112
}

Return to bug 256496