浏览代码

add lifecycle methods for activation / deactivation of pinned editor (#2034)

Andreas Mülder 7 年之前
父节点
当前提交
3780301c29

+ 1 - 1
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -588,7 +588,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 
 
 	@Check(CheckType.FAST)
 	@Check(CheckType.FAST)
 	public void checkAnnotationArguments(ArgumentedAnnotation annotation) {
 	public void checkAnnotationArguments(ArgumentedAnnotation annotation) {
-		if (annotation.getExpressions().size() != annotation.getType().getProperties().size()) {
+		if (annotation.getType() != null && annotation.getExpressions().size() != annotation.getType().getProperties().size()) {
 			error(String.format(ERROR_WRONG_NUMBER_OF_ARGUMENTS_MSG, annotation.getType().getProperties()), null,
 			error(String.format(ERROR_WRONG_NUMBER_OF_ARGUMENTS_MSG, annotation.getType().getProperties()), null,
 					ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
 					ERROR_WRONG_NUMBER_OF_ARGUMENTS_CODE);
 		}
 		}

+ 61 - 55
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/definitionsection/StatechartDefinitionSection.java

@@ -74,7 +74,6 @@ import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.resource.XtextResource;
 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditor;
 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
 import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorFactory;
-import org.eclipse.xtext.ui.editor.embedded.EmbeddedEditorModelAccess;
 import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
 import org.eclipse.xtext.ui.editor.embedded.IEditedResourceProvider;
 import org.yakindu.base.base.BasePackage;
 import org.yakindu.base.base.BasePackage;
 import org.yakindu.base.base.NamedElement;
 import org.yakindu.base.base.NamedElement;
@@ -103,7 +102,6 @@ import com.google.inject.Injector;
 public class StatechartDefinitionSection extends Composite
 public class StatechartDefinitionSection extends Composite
 		implements IPersistableEditor, IPersistableElement, IContextElementProvider {
 		implements IPersistableEditor, IPersistableElement, IContextElementProvider {
 
 
-	protected static final String INLINE_TOOLTIP = "Inline definition section";
 	protected static final String SHOW_SECTION_TOOLTIP = "Show definition section";
 	protected static final String SHOW_SECTION_TOOLTIP = "Show definition section";
 	protected static final String HIDE_SECTION_TOOLTIP = "Hide definition section";
 	protected static final String HIDE_SECTION_TOOLTIP = "Hide definition section";
 
 
@@ -117,7 +115,7 @@ public class StatechartDefinitionSection extends Composite
 	protected static final int[] MIN_SIZE = { 11, 21 };
 	protected static final int[] MIN_SIZE = { 11, 21 };
 	protected static final int[] DEFAULT_WEIGHTS = new int[] { 2, 10 };
 	protected static final int[] DEFAULT_WEIGHTS = new int[] { 2, 10 };
 	protected int[] previousWidths = DEFAULT_WEIGHTS;
 	protected int[] previousWidths = DEFAULT_WEIGHTS;
-	private boolean isSectionExpanded = true;
+	private boolean sectionExpanded = true;
 
 
 	private MouseListener mouseListener;
 	private MouseListener mouseListener;
 	private ResizeListener resizeListener;
 	private ResizeListener resizeListener;
@@ -134,6 +132,7 @@ public class StatechartDefinitionSection extends Composite
 	private DiagramPartitioningEditor editorPart;
 	private DiagramPartitioningEditor editorPart;
 
 
 	private static IMemento memento;
 	private static IMemento memento;
+	private ValidatingEMFDatabindingContext context;
 
 
 	public StatechartDefinitionSection(Composite parent, int style, DiagramPartitioningEditor editorPart) {
 	public StatechartDefinitionSection(Composite parent, int style, DiagramPartitioningEditor editorPart) {
 		super(parent, style);
 		super(parent, style);
@@ -148,8 +147,8 @@ public class StatechartDefinitionSection extends Composite
 
 
 	protected Label createSwitchControl() {
 	protected Label createSwitchControl() {
 		Label switchControl = new Label(this, SWT.PUSH);
 		Label switchControl = new Label(this, SWT.PUSH);
-		switchControl.setToolTipText(isSectionExpanded ? HIDE_SECTION_TOOLTIP : SHOW_SECTION_TOOLTIP);
-		switchControl.setImage(isSectionExpanded ? StatechartImages.COLLAPSE.image() : StatechartImages.EXPAND.image());
+		switchControl.setToolTipText(sectionExpanded ? HIDE_SECTION_TOOLTIP : SHOW_SECTION_TOOLTIP);
+		switchControl.setImage(sectionExpanded ? StatechartImages.COLLAPSE.image() : StatechartImages.EXPAND.image());
 		switchControl.setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));
 		switchControl.setCursor(new Cursor(getDisplay(), SWT.CURSOR_HAND));
 		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(-1, -1).hint(MIN_SIZE[0], MIN_SIZE[1])
 		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(-1, -1).hint(MIN_SIZE[0], MIN_SIZE[1])
 				.applyTo(switchControl);
 				.applyTo(switchControl);
@@ -229,11 +228,15 @@ public class StatechartDefinitionSection extends Composite
 
 
 	protected EmbeddedEditor createSpecificationEditor() {
 	protected EmbeddedEditor createSpecificationEditor() {
 		EmbeddedEditor embeddedEditor = createEmbeddedEditor();
 		EmbeddedEditor embeddedEditor = createEmbeddedEditor();
-		EmbeddedEditorModelAccess modelAccess = embeddedEditor.createPartialEditor();
-		String specification = ((Statechart) getContextObject()).getSpecification();
-		modelAccess.updateModel(specification != null ? specification : "");
+		embeddedEditor.createPartialEditor();
 		GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
 		GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(embeddedEditor.getViewer().getControl());
-		initializeEmbeddedEditorWidget(embeddedEditor);
+		StyledText text = embeddedEditor.getViewer().getTextWidget();
+		text.setAlwaysShowScrollBars(false);
+		text.setSelection(0);
+		text.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
+		initXtextSelectionProvider(text);
+		initContextMenu(text);
+		text.addModifyListener((event) -> editorPart.firePropertyChange(IEditorPart.PROP_DIRTY));
 		return embeddedEditor;
 		return embeddedEditor;
 	}
 	}
 
 
@@ -262,17 +265,6 @@ public class StatechartDefinitionSection extends Composite
 		};
 		};
 	}
 	}
 
 
-	protected void initializeEmbeddedEditorWidget(EmbeddedEditor embeddedEditor) {
-		StyledText embeddedEditorWidget = embeddedEditor.getViewer().getTextWidget();
-		embeddedEditorWidget.setAlwaysShowScrollBars(false);
-		embeddedEditorWidget.setSelection(0);
-		embeddedEditorWidget.setKeyBinding(SWT.MOD1 | SWT.KEY_MASK & 'a', ST.SELECT_ALL);
-		initXtextSelectionProvider(embeddedEditorWidget);
-		initBinding(embeddedEditorWidget);
-		initContextMenu(embeddedEditorWidget);
-		embeddedEditorWidget.addModifyListener((event) -> editorPart.firePropertyChange(IEditorPart.PROP_DIRTY));
-	}
-
 	@SuppressWarnings("unused")
 	@SuppressWarnings("unused")
 	protected void initXtextSelectionProvider(StyledText widget) {
 	protected void initXtextSelectionProvider(StyledText widget) {
 		try {
 		try {
@@ -284,15 +276,25 @@ public class StatechartDefinitionSection extends Composite
 		}
 		}
 	}
 	}
 
 
+	protected void activate() {
+		initBinding(embeddedEditor.getViewer().getTextWidget());
+		getSash().setMaximizedControl(null);
+	}
+
+	protected void deactivate() {
+		getSash().setMaximizedControl(getSash().getChildren()[MAXIMIZED_CONTROL_INDEX]);
+		if (context != null)
+			context.dispose();
+	}
+
 	@SuppressWarnings({ "unchecked", "rawtypes" })
 	@SuppressWarnings({ "unchecked", "rawtypes" })
-	protected void initBinding(StyledText embeddedEditorWidget) {
+	protected void initBinding(StyledText text) {
 		IEMFValueProperty modelProperty = EMFEditProperties.value(getTransactionalEditingDomain(),
 		IEMFValueProperty modelProperty = EMFEditProperties.value(getTransactionalEditingDomain(),
 				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
 				SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
-		ISWTObservableValue uiProperty = WidgetProperties.text(new int[] { SWT.FocusOut })
-				.observe(embeddedEditorWidget);
+		ISWTObservableValue uiProperty = WidgetProperties.text(new int[] { SWT.FocusOut }).observe(text);
 		IObservableValue modelPropertyObservable = modelProperty.observe(getContextObject());
 		IObservableValue modelPropertyObservable = modelProperty.observe(getContextObject());
-		ValidatingEMFDatabindingContext context = new ValidatingEMFDatabindingContext(
-				(IContextElementProvider) editorPart, editorPart.getSite().getShell());
+		context = new ValidatingEMFDatabindingContext((IContextElementProvider) editorPart,
+				editorPart.getSite().getShell());
 		context.bindValue(uiProperty, modelPropertyObservable, null, null);
 		context.bindValue(uiProperty, modelPropertyObservable, null, null);
 	}
 	}
 
 
@@ -325,31 +327,33 @@ public class StatechartDefinitionSection extends Composite
 		return (Diagram) editorPart.getAdapter(Diagram.class);
 		return (Diagram) editorPart.getAdapter(Diagram.class);
 	}
 	}
 
 
-	protected void updateInlineStyle() {
+	protected void toggleDefinitionSection() {
+		toggleInlineStyle();
+		updateStyle();
+		refreshEditorContents();
+	}
+
+	private void toggleInlineStyle() {
 		TransactionalEditingDomain domain = getTransactionalEditingDomain();
 		TransactionalEditingDomain domain = getTransactionalEditingDomain();
 		Diagram diagram = getDiagram();
 		Diagram diagram = getDiagram();
 		BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(diagram);
 		BooleanValueStyle inlineStyle = DiagramPartitioningUtil.getInlineDefinitionSectionStyle(diagram);
 		if (inlineStyle == null) {
 		if (inlineStyle == null) {
 			inlineStyle = DiagramPartitioningUtil.createInlineDefinitionSectionStyle();
 			inlineStyle = DiagramPartitioningUtil.createInlineDefinitionSectionStyle();
-			addInlineStyle(inlineStyle, domain);
+			AddCommand command = new AddCommand(domain, (View) getDiagram(), NotationPackage.Literals.VIEW__STYLES,
+					inlineStyle);
+			domain.getCommandStack().execute(command);
 		}
 		}
-		setInlineStyleValue(inlineStyle, domain);
-	}
-
-	protected void setInlineStyleValue(BooleanValueStyle inlineStyle, TransactionalEditingDomain domain) {
 		SetCommand command = new SetCommand(domain, inlineStyle,
 		SetCommand command = new SetCommand(domain, inlineStyle,
 				NotationPackage.Literals.BOOLEAN_VALUE_STYLE__BOOLEAN_VALUE, !inlineStyle.isBooleanValue());
 				NotationPackage.Literals.BOOLEAN_VALUE_STYLE__BOOLEAN_VALUE, !inlineStyle.isBooleanValue());
 		domain.getCommandStack().execute(command);
 		domain.getCommandStack().execute(command);
 	}
 	}
 
 
-	protected void addInlineStyle(BooleanValueStyle inlineStyle, TransactionalEditingDomain domain) {
-		AddCommand command = new AddCommand(domain, (View) getDiagram(), NotationPackage.Literals.VIEW__STYLES,
-				inlineStyle);
-		domain.getCommandStack().execute(command);
-	}
-
-	public void toggleDefinitionSection() {
-		getSash().setMaximizedControl(!isInlined() ? null : getSash().getChildren()[MAXIMIZED_CONTROL_INDEX]);
+	public void updateStyle() {
+		if (isInlined()) {
+			deactivate();
+		} else {
+			activate();
+		}
 	}
 	}
 
 
 	protected boolean isInlined() {
 	protected boolean isInlined() {
@@ -398,8 +402,8 @@ public class StatechartDefinitionSection extends Composite
 
 
 	protected void toggleExpandState() {
 	protected void toggleExpandState() {
 		getSash().setRedraw(false);
 		getSash().setRedraw(false);
-		isSectionExpanded = !isSectionExpanded;
-		if (isSectionExpanded) {
+		sectionExpanded = !sectionExpanded;
+		if (sectionExpanded) {
 			expandDefinitionSection();
 			expandDefinitionSection();
 		} else {
 		} else {
 			collapseDefinitionSection();
 			collapseDefinitionSection();
@@ -494,7 +498,7 @@ public class StatechartDefinitionSection extends Composite
 			Boolean hasMemento = getExpandProperty(memento);
 			Boolean hasMemento = getExpandProperty(memento);
 			if (hasMemento != null) {
 			if (hasMemento != null) {
 				previousWidths = getWeightProperties(memento);
 				previousWidths = getWeightProperties(memento);
-				isSectionExpanded = hasMemento.booleanValue();
+				sectionExpanded = hasMemento.booleanValue();
 				refreshEditorContents();
 				refreshEditorContents();
 				saveCurrentMemento(memento);
 				saveCurrentMemento(memento);
 			} else {
 			} else {
@@ -512,7 +516,7 @@ public class StatechartDefinitionSection extends Composite
 		String sectionProperty = getSectionProperty(getContextObject());
 		String sectionProperty = getSectionProperty(getContextObject());
 		memento.putInteger(sectionProperty + MEM_FIRST_WEIGHT, previousWidths[0]);
 		memento.putInteger(sectionProperty + MEM_FIRST_WEIGHT, previousWidths[0]);
 		memento.putInteger(sectionProperty + MEM_SECOND_WEIGHT, previousWidths[1]);
 		memento.putInteger(sectionProperty + MEM_SECOND_WEIGHT, previousWidths[1]);
-		memento.putBoolean(sectionProperty + MEM_EXPANDED, isSectionExpanded);
+		memento.putBoolean(sectionProperty + MEM_EXPANDED, sectionExpanded);
 	}
 	}
 
 
 	protected String getSectionProperty(EObject element) {
 	protected String getSectionProperty(EObject element) {
@@ -539,6 +543,12 @@ public class StatechartDefinitionSection extends Composite
 		return DEFAULT_WEIGHTS;
 		return DEFAULT_WEIGHTS;
 	}
 	}
 
 
+	public String getDefinition() {
+		if (isInlined())
+			return null;
+		return embeddedEditor.getDocument().get();
+	}
+
 	/**
 	/**
 	 * @author robert rudi - Initial contribution and API
 	 * @author robert rudi - Initial contribution and API
 	 * 
 	 * 
@@ -556,7 +566,7 @@ public class StatechartDefinitionSection extends Composite
 					public void run() {
 					public void run() {
 						if (isDisposed() || getSash().isDisposed())
 						if (isDisposed() || getSash().isDisposed())
 							return;
 							return;
-						if (isSectionExpanded) {
+						if (sectionExpanded) {
 							// save current weights so the widths can later be restored
 							// save current weights so the widths can later be restored
 							previousWidths = getSash().getWeights();
 							previousWidths = getSash().getWeights();
 							saveState(memento);
 							saveState(memento);
@@ -586,6 +596,7 @@ public class StatechartDefinitionSection extends Composite
 			resizeFinishedJob.cancel();
 			resizeFinishedJob.cancel();
 			resizeFinishedJob.schedule(DELAY);
 			resizeFinishedJob.schedule(DELAY);
 		}
 		}
+		
 	}
 	}
 
 
 	/**
 	/**
@@ -594,6 +605,7 @@ public class StatechartDefinitionSection extends Composite
 	 */
 	 */
 	protected class InlineIcon extends Composite implements MouseListener, MouseTrackListener, PaintListener {
 	protected class InlineIcon extends Composite implements MouseListener, MouseTrackListener, PaintListener {
 
 
+		protected static final String INLINE_TOOLTIP = "Inline definition section";
 		private Cursor handCursor = new Cursor(getDisplay(), SWT.CURSOR_HAND);
 		private Cursor handCursor = new Cursor(getDisplay(), SWT.CURSOR_HAND);
 		private boolean iconHasFocus = false;
 		private boolean iconHasFocus = false;
 		private Label icon;
 		private Label icon;
@@ -613,9 +625,7 @@ public class StatechartDefinitionSection extends Composite
 
 
 		@Override
 		@Override
 		public void mouseUp(MouseEvent e) {
 		public void mouseUp(MouseEvent e) {
-			updateInlineStyle();
 			toggleDefinitionSection();
 			toggleDefinitionSection();
-			refreshEditorContents();
 			saveState(memento);
 			saveState(memento);
 		}
 		}
 
 
@@ -709,26 +719,26 @@ public class StatechartDefinitionSection extends Composite
 			e.gc.setTransform(tr);
 			e.gc.setTransform(tr);
 			tr.dispose();
 			tr.dispose();
 			int drawHeight = -w + 2;
 			int drawHeight = -w + 2;
-			e.gc.drawString(isSectionExpanded ? "" : text, 0, drawHeight % 2 != 0 ? drawHeight + 1 : drawHeight - 1);
+			e.gc.drawString(sectionExpanded ? "" : text, 0, drawHeight % 2 != 0 ? drawHeight + 1 : drawHeight - 1);
 		}
 		}
 
 
 		@Override
 		@Override
 		public void mouseUp(MouseEvent e) {
 		public void mouseUp(MouseEvent e) {
-			if (!isSectionExpanded)
+			if (!sectionExpanded)
 				toggleExpandState();
 				toggleExpandState();
 			setCursor(arrowCursor);
 			setCursor(arrowCursor);
 		}
 		}
 
 
 		@Override
 		@Override
 		public void mouseDown(MouseEvent e) {
 		public void mouseDown(MouseEvent e) {
-			if (mouseListener != null && !isSectionExpanded)
+			if (mouseListener != null && !sectionExpanded)
 				toggleExpandState();
 				toggleExpandState();
 		}
 		}
 
 
 		@Override
 		@Override
 		public void mouseEnter(MouseEvent e) {
 		public void mouseEnter(MouseEvent e) {
-			setCursor((!isSectionExpanded) ? handCursor : arrowCursor);
-			setToolTipText((!isSectionExpanded) ? SHOW_SECTION_TOOLTIP : null);
+			setCursor((!sectionExpanded) ? handCursor : arrowCursor);
+			setToolTipText((!sectionExpanded) ? SHOW_SECTION_TOOLTIP : null);
 		}
 		}
 
 
 		@Override
 		@Override
@@ -754,8 +764,4 @@ public class StatechartDefinitionSection extends Composite
 			super.dispose();
 			super.dispose();
 		}
 		}
 	}
 	}
-
-	public String getDefinition() {
-		return embeddedEditor.getDocument().get();
-	}
 }
 }

+ 1 - 1
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/editor/StatechartDiagramEditor.java

@@ -415,7 +415,7 @@ public class StatechartDiagramEditor extends DiagramPartitioningEditor implement
 
 
 	public void toggleDefinitionSection() {
 	public void toggleDefinitionSection() {
 		if (definitionSection != null && !definitionSection.isDisposed() && isStatechart()) {
 		if (definitionSection != null && !definitionSection.isDisposed() && isStatechart()) {
-			definitionSection.toggleDefinitionSection();
+			definitionSection.updateStyle();
 			definitionSection.restoreSashWidths();
 			definitionSection.restoreSashWidths();
 		}
 		}
 	}
 	}