001: package newprocess.diagram.part;
002:
003: import newprocess.diagram.cust.annotations.contributor.ContextMenuListener;
004:
005: import org.eclipse.core.resources.IFile;
006: import org.eclipse.core.resources.IMarker;
007: import org.eclipse.core.resources.IWorkspaceRoot;
008: import org.eclipse.core.resources.ResourcesPlugin;
009: import org.eclipse.core.runtime.CoreException;
010: import org.eclipse.core.runtime.IPath;
011: import org.eclipse.core.runtime.IProgressMonitor;
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.core.runtime.NullProgressMonitor;
014: import org.eclipse.emf.common.notify.Adapter;
015: import org.eclipse.emf.common.notify.Notification;
016: import org.eclipse.emf.common.notify.Notifier;
017: import org.eclipse.emf.ecore.resource.Resource;
018: import org.eclipse.emf.ecore.resource.ResourceSet;
019: import org.eclipse.emf.transaction.NotificationFilter;
020: import org.eclipse.emf.transaction.TransactionalEditingDomain;
021: import org.eclipse.gef.GraphicalViewer;
022: import org.eclipse.gef.palette.PaletteRoot;
023: import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
024: import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
025: import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
026: import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
027: import org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.document.StorageDiagramDocumentProvider;
028: import org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor;
029: import org.eclipse.jface.action.MenuManager;
030: import org.eclipse.jface.dialogs.ErrorDialog;
031: import org.eclipse.jface.dialogs.IMessageProvider;
032: import org.eclipse.jface.dialogs.MessageDialog;
033: import org.eclipse.jface.window.Window;
034: import org.eclipse.osgi.util.NLS;
035: import org.eclipse.swt.widgets.Shell;
036: import org.eclipse.ui.IEditorInput;
037: import org.eclipse.ui.IEditorMatchingStrategy;
038: import org.eclipse.ui.IEditorReference;
039: import org.eclipse.ui.IFileEditorInput;
040: import org.eclipse.ui.PlatformUI;
041: import org.eclipse.ui.dialogs.SaveAsDialog;
042: import org.eclipse.ui.ide.IGotoMarker;
043: import org.eclipse.ui.part.FileEditorInput;
044:
045: /**
046: * @generated
047: */
048: public class New_processDiagramEditor extends DiagramDocumentEditor
049: implements IGotoMarker {
050:
051: /**
052: * @generated
053: */
054: public static final String ID = "newprocess.diagram.part.New_processDiagramEditorID"; //$NON-NLS-1$
055:
056: /**
057: * @generated
058: */
059: public New_processDiagramEditor() {
060: super (true);
061: }
062:
063: /**
064: * @generated
065: */
066: protected String getEditingDomainID() {
067: return "org.concept.diagram.EditingDomain"; //$NON-NLS-1$
068: }
069:
070: /**
071: * @generated
072: */
073: protected TransactionalEditingDomain createEditingDomain() {
074: TransactionalEditingDomain domain = super .createEditingDomain();
075: domain.setID(getEditingDomainID());
076: final NotificationFilter diagramResourceModifiedFilter = NotificationFilter
077: .createNotifierFilter(domain.getResourceSet())
078: .and(
079: NotificationFilter
080: .createEventTypeFilter(Notification.ADD))
081: .and(
082: NotificationFilter.createFeatureFilter(
083: ResourceSet.class,
084: ResourceSet.RESOURCE_SET__RESOURCES));
085: domain.getResourceSet().eAdapters().add(new Adapter() {
086:
087: private Notifier myTarger;
088:
089: public Notifier getTarget() {
090: return myTarger;
091: }
092:
093: public boolean isAdapterForType(Object type) {
094: return false;
095: }
096:
097: public void notifyChanged(Notification notification) {
098: if (diagramResourceModifiedFilter.matches(notification)) {
099: Object value = notification.getNewValue();
100: if (value instanceof Resource) {
101: ((Resource) value)
102: .setTrackingModification(true);
103: }
104: }
105: }
106:
107: public void setTarget(Notifier newTarget) {
108: myTarger = newTarget;
109: }
110:
111: });
112:
113: return domain;
114: }
115:
116: /**
117: * @generated
118: */
119: protected PaletteRoot createPaletteRoot(
120: PaletteRoot existingPaletteRoot) {
121: PaletteRoot root = super .createPaletteRoot(existingPaletteRoot);
122: new New_processPaletteFactory().fillPalette(root);
123: return root;
124: }
125:
126: /**
127: * @generated
128: */
129: protected PreferencesHint getPreferencesHint() {
130: return New_processDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
131: }
132:
133: /**
134: * @generated
135: */
136: public String getContributorId() {
137: return New_processDiagramEditorPlugin.ID;
138: }
139:
140: /**
141: * @generated
142: */
143: private String contentObjectURI;
144:
145: /**
146: * @generated
147: */
148: protected void setDocumentProvider(IEditorInput input) {
149: if (input instanceof IFileEditorInput) {
150: setDocumentProvider(new New_processDocumentProvider(
151: contentObjectURI));
152: } else {
153: setDocumentProvider(new StorageDiagramDocumentProvider());
154: }
155: }
156:
157: /**
158: * @generated
159: */
160: public void gotoMarker(IMarker marker) {
161: MarkerNavigationService.getInstance().gotoMarker(this , marker);
162: }
163:
164: /**
165: * @generated
166: */
167: public boolean isSaveAsAllowed() {
168: return true;
169: }
170:
171: /**
172: * @generated
173: */
174: public void doSaveAs() {
175: performSaveAs(new NullProgressMonitor());
176: }
177:
178: /**
179: * @generated
180: */
181: protected void performSaveAs(IProgressMonitor progressMonitor) {
182: Shell shell = getSite().getShell();
183: IEditorInput input = getEditorInput();
184: SaveAsDialog dialog = new SaveAsDialog(shell);
185: IFile original = input instanceof IFileEditorInput ? ((IFileEditorInput) input)
186: .getFile()
187: : null;
188: if (original != null) {
189: dialog.setOriginalFile(original);
190: }
191: dialog.create();
192: IDocumentProvider provider = getDocumentProvider();
193: if (provider == null) {
194: // editor has been programmatically closed while the dialog was open
195: return;
196: }
197: if (provider.isDeleted(input) && original != null) {
198: String message = NLS.bind(
199: "The original file ''{0}'' has been deleted.",
200: original.getName());
201: dialog.setErrorMessage(null);
202: dialog.setMessage(message, IMessageProvider.WARNING);
203: }
204: if (dialog.open() == Window.CANCEL) {
205: if (progressMonitor != null) {
206: progressMonitor.setCanceled(true);
207: }
208: return;
209: }
210: IPath filePath = dialog.getResult();
211: if (filePath == null) {
212: if (progressMonitor != null) {
213: progressMonitor.setCanceled(true);
214: }
215: return;
216: }
217: IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
218: .getRoot();
219: IFile file = workspaceRoot.getFile(filePath);
220: final IEditorInput newInput = new FileEditorInput(file);
221: // Check if the editor is already open
222: IEditorMatchingStrategy matchingStrategy = getEditorDescriptor()
223: .getEditorMatchingStrategy();
224: IEditorReference[] editorRefs = PlatformUI.getWorkbench()
225: .getActiveWorkbenchWindow().getActivePage()
226: .getEditorReferences();
227: for (int i = 0; i < editorRefs.length; i++) {
228: if (matchingStrategy.matches(editorRefs[i], newInput)) {
229: MessageDialog
230: .openWarning(shell,
231: "Problem During Save As...",
232: "Save could not be completed. Target file is already open in another editor.");
233: return;
234: }
235: }
236: boolean success = false;
237: try {
238: provider.aboutToChange(newInput);
239: getDocumentProvider(newInput)
240: .saveDocument(
241: progressMonitor,
242: newInput,
243: getDocumentProvider().getDocument(
244: getEditorInput()), true);
245: success = true;
246: } catch (CoreException x) {
247: IStatus status = x.getStatus();
248: if (status == null
249: || status.getSeverity() != IStatus.CANCEL) {
250: ErrorDialog.openError(shell, "Save Problems",
251: "Could not save file.", x.getStatus());
252: }
253: } finally {
254: provider.changed(newInput);
255: if (success) {
256: setInput(newInput);
257: }
258: }
259: if (progressMonitor != null) {
260: progressMonitor.setCanceled(!success);
261: }
262: }
263:
264: /**
265: * @author sh
266: * @see DiagramEditor#configureGraphicalViewer()
267: */
268: protected void configureGraphicalViewer() {
269: super .configureGraphicalViewer();
270:
271: /*
272: * SH:
273: * 1. fetch a files project to know which project
274: * concerns to our Annotations
275: * 2. adding a MenuListener for contributing Annotation
276: * entries.
277: */
278: IEditorInput input = getEditorInput();
279: IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
280: .getFile()
281: : null;
282:
283: MenuManager dmgr = getDiagramGraphicalViewer().getContextMenu();
284: GraphicalViewer viewer = getGraphicalViewer();
285: dmgr.addMenuListener(new ContextMenuListener(viewer, original
286: .getProject()));
287: }
288: }
|