|
|
@@ -10,6 +10,9 @@
|
|
|
*/
|
|
|
package org.yakindu.sct.ui.editor.editor;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Optional;
|
|
|
+
|
|
|
import org.eclipse.core.resources.IMarker;
|
|
|
import org.eclipse.core.resources.IProject;
|
|
|
import org.eclipse.core.resources.IProjectDescription;
|
|
|
@@ -34,6 +37,8 @@ import org.eclipse.jface.layout.GridDataFactory;
|
|
|
import org.eclipse.swt.SWT;
|
|
|
import org.eclipse.swt.widgets.Composite;
|
|
|
import org.eclipse.ui.IEditorInput;
|
|
|
+import org.eclipse.ui.IEditorPart;
|
|
|
+import org.eclipse.ui.IEditorReference;
|
|
|
import org.eclipse.ui.IEditorSite;
|
|
|
import org.eclipse.ui.IFileEditorInput;
|
|
|
import org.eclipse.ui.PartInitException;
|
|
|
@@ -58,6 +63,7 @@ import org.yakindu.sct.ui.editor.utils.HelpContextIds;
|
|
|
import org.yakindu.sct.ui.editor.validation.IValidationIssueStore;
|
|
|
import org.yakindu.sct.ui.editor.validation.LiveValidationListener;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.google.inject.Injector;
|
|
|
import com.google.inject.Key;
|
|
|
|
|
|
@@ -133,8 +139,7 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
|
|
|
}
|
|
|
|
|
|
protected void registerValidationListener() {
|
|
|
- issueStore = getEditorInjector().getInstance(IValidationIssueStore.class);
|
|
|
- issueStore.connect(getDiagram().eResource());
|
|
|
+ issueStore = getIssueStore();
|
|
|
validationListener = getEditorInjector().getInstance(LiveValidationListener.class);
|
|
|
validationListener.setResource(getDiagram().eResource());
|
|
|
validationListener.setValidationIssueProcessor(issueStore);
|
|
|
@@ -142,6 +147,38 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
|
|
|
validationListener.scheduleValidation();
|
|
|
}
|
|
|
|
|
|
+ protected IValidationIssueStore getIssueStore() {
|
|
|
+ Optional<IEditorPart> editorWithSameResource = getEditorWithSameResource();
|
|
|
+ if (editorWithSameResource.isPresent()) {
|
|
|
+ IValidationIssueStore sharedStore = editorWithSameResource.get()
|
|
|
+ .getAdapter(IValidationIssueStore.class);
|
|
|
+ return sharedStore;
|
|
|
+ } else {
|
|
|
+ IValidationIssueStore newStore = getEditorInjector().getInstance(IValidationIssueStore.class);
|
|
|
+ newStore.connect(getDiagram().eResource());
|
|
|
+ return newStore;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected Optional<IEditorPart> getEditorWithSameResource() {
|
|
|
+ ArrayList<IEditorReference> currentEditors = Lists.newArrayList(
|
|
|
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences());
|
|
|
+
|
|
|
+ Optional<IEditorPart> editorWithSameResource = currentEditors.stream().filter(e -> {
|
|
|
+ try {
|
|
|
+ IEditorInput otherInput = e.getEditorInput();
|
|
|
+ IEditorInput thisInput = this.getEditorInput();
|
|
|
+
|
|
|
+ return ID.equals(e.getId()) && !otherInput.equals(thisInput) && ((IFileEditorInput) otherInput)
|
|
|
+ .getFile().getLocationURI().equals(((IFileEditorInput) thisInput).getFile().getLocationURI());
|
|
|
+ } catch (PartInitException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }).map(e -> e.getEditor(false)).findFirst();
|
|
|
+ return editorWithSameResource;
|
|
|
+ }
|
|
|
+
|
|
|
protected Injector getEditorInjector() {
|
|
|
IDomain domain = DomainRegistry.getDomain(getDiagram().getElement());
|
|
|
Injector injector = domain.getInjector(IDomain.FEATURE_EDITOR);
|
|
|
@@ -294,8 +331,9 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
|
|
|
if (validationListener != null) {
|
|
|
validationListener.dispose();
|
|
|
}
|
|
|
- if (issueStore != null)
|
|
|
+ if (issueStore != null && !getEditorWithSameResource().isPresent()) {
|
|
|
issueStore.disconnect(getDiagram().eResource());
|
|
|
+ }
|
|
|
getEditingDomain().removeResourceSetListener(validationListener);
|
|
|
getEditingDomain().removeResourceSetListener(domainAdapter);
|
|
|
if (domainAdapter != null)
|
|
|
@@ -303,6 +341,7 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
protected int getInitialPaletteSize() {
|
|
|
return INITIAL_PALETTE_SIZE;
|