Browse files

JBPM-3149 fix for multiple editor openings

  • Loading branch information...
1 parent 584fd03 commit fda31bee77a997bc6ded0c27f3aaf519a832ac40 @imeikas committed Mar 22, 2011
View
7 org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/editor/BPMN2Editor.java
@@ -43,7 +43,6 @@
import org.jboss.bpmn2.editor.ui.wizards.BPMN2DiagramCreator;
/**
- * @author if
*
*/
@SuppressWarnings("restriction")
@@ -95,8 +94,6 @@ private void getModelPathFromInput(DiagramEditorInput input) {
* Beware, creates a new input and changes this editor!
*/
private IEditorInput createNewDiagramEditorInput() throws CoreException {
- IEditorInput input;
- BPMN2DiagramCreator creator = new BPMN2DiagramCreator();
IPath fullPath = modelFile.getFullPath();
modelUri = URI.createPlatformResourceURI(fullPath.toString(), true);
@@ -105,10 +102,12 @@ private IEditorInput createNewDiagramEditorInput() throws CoreException {
.getTempFile(fullPath.removeFileExtension().addFileExtension("bpmn2d"), folder);
// Create new temporary diagram file
+ BPMN2DiagramCreator creator = new BPMN2DiagramCreator();
creator.setDiagramFile(diagramFile);
- input = creator.createDiagram(false);
+ IEditorInput input = creator.createDiagram(false);
diagramUri = creator.getUri();
+
return input;
}
View
6 org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/wizards/BPMN2DiagramCreator.java
@@ -31,9 +31,6 @@
import org.jboss.bpmn2.editor.ui.editor.BPMN2Editor;
import org.jboss.bpmn2.editor.ui.util.ErrorUtils;
-/**
- *
- */
public class BPMN2DiagramCreator {
private IFolder diagramFolder;
@@ -56,7 +53,8 @@ public DiagramEditorInput createDiagram(boolean openEditor) throws CoreException
TransactionalEditingDomain domain = FileService.createEmfFileForDiagram(uri, diagram);
String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
- final DiagramEditorInput editorInput = new DiagramEditorInput(EcoreUtil.getURI(diagram), domain, providerId);
+ final DiagramEditorInput editorInput = new Bpmn2DiagramEditorInput(EcoreUtil.getURI(diagram), domain,
+ providerId);
if (openEditor) {
openEditor(editorInput);
View
51 org.jboss.bpmn2.editor.ui/src/org/jboss/bpmn2/editor/ui/wizards/Bpmn2DiagramEditorInput.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.bpmn2.editor.ui.wizards;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+
+final class Bpmn2DiagramEditorInput extends DiagramEditorInput {
+
+ private final TransactionalEditingDomain domain;
+
+ Bpmn2DiagramEditorInput(URI diagramUri, TransactionalEditingDomain domain, String providerId) {
+ super(diagramUri, domain, providerId);
+ this.domain = domain;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean superEquals = super.equals(obj);
+ if (superEquals) {
+ return true;
+ }
+
+ // Eclipse makes FileEditorInputs for files to be opened. Here we check if the file is actually the same
+ // as the DiagramEditorInput uses. This is for preventing opening new editors for the same file.
+ if (obj instanceof FileEditorInput) {
+
+ String path = ((FileEditorInput) obj).getFile().getFullPath().toString();
+ URI platformUri = URI.createPlatformResourceURI(path, true);
+
+ for (Resource resource : domain.getResourceSet().getResources()) {
+ if (resource.getURI().equals(platformUri)) {
+ return true;
+ }
+ }
+
+ }
+ return false;
+ }
+}

0 comments on commit fda31be

Please sign in to comment.