Просмотр исходного кода

Added SashForm to two column property pages

Andreas Mülder 13 лет назад
Родитель
Сommit
1dc483dc13

+ 46 - 0
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/AbstractTwoColumnEditorPropertySection.java

@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2011 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.ui.editor.propertysheets;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public abstract class AbstractTwoColumnEditorPropertySection extends
+		AbstractEditorPropertySection {
+
+	protected abstract void createRightColumnControls(Composite rightColumn);
+
+	protected abstract void createLeftColumnControls(Composite leftColumn);
+
+	@Override
+	public void createControls(Composite parent) {
+		parent.setLayout(new FillLayout());
+		SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL | SWT.SMOOTH);
+		sashForm.setSashWidth(5);
+		sashForm.setBackground(ColorConstants.white);
+		sashForm.setLayout(new FillLayout());
+		Composite leftColumn = getToolkit().createComposite(sashForm);
+		leftColumn.setLayout(createBodyLayout());
+		Composite rightColumn = getToolkit().createComposite(sashForm);
+		rightColumn.setLayout(createBodyLayout());
+		sashForm.setWeights(new int[]{2,3});
+		createLeftColumnControls(leftColumn);
+		createRightColumnControls(rightColumn);
+	}
+
+}

+ 28 - 16
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatePropertySection.java

@@ -30,7 +30,6 @@ import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
@@ -55,29 +54,28 @@ import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResour
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class StatePropertySection extends AbstractEditorPropertySection
-		implements ISourceObjectCallback {
+public class StatePropertySection extends
+		AbstractTwoColumnEditorPropertySection implements ISourceObjectCallback {
 
 	private Label lblSubmachine;
 	private Control txtSpecification;
 	private Control txtName;
 
-	private UpdateLabelAdapter updateLabelAdapter;
+	private UpdateLabelAdapter updateLabelAdapter = new UpdateLabelAdapter();
 	private OrderElementControl orderElementControl;
 
 	@Override
-	public void createControls(final Composite parent) {
-		parent.setLayout(new FillLayout());
-		Composite leftColumn = getToolkit().createComposite(parent);
-		leftColumn.setLayout(new FillLayout());
-		Composite rightColumn = getToolkit().createComposite(parent);
-		rightColumn.setLayout(createBodyLayout());
+	protected void createRightColumnControls(Composite rightColumn) {
 		createNameControl(rightColumn);
-		createSpecificationControl(leftColumn);
 		createSubmachineControl(rightColumn);
 		createTransitionsControl(rightColumn);
 	}
 
+	@Override
+	protected void createLeftColumnControls(Composite leftColumn) {
+		createSpecificationControl(leftColumn);
+	}
+
 	private void createNameControl(final Composite parent) {
 		Label lblName = getToolkit().createLabel(parent, "State Name: ");
 		txtName = getToolkit().createText(parent, "");
@@ -98,6 +96,7 @@ public class StatePropertySection extends AbstractEditorPropertySection
 		} else {
 			txtSpecification = getToolkit().createText(parent, "", SWT.MULTI);
 		}
+		GridDataFactory.fillDefaults().grab(true, true).applyTo(txtSpecification);
 	}
 
 	private void createSubmachineControl(final Composite parent) {
@@ -136,10 +135,6 @@ public class StatePropertySection extends AbstractEditorPropertySection
 	public void bindModel(EMFDataBindingContext context) {
 		bindNameControl(context);
 		bindSpecificationControl(context);
-		if (updateLabelAdapter == null) {
-			updateLabelAdapter = new UpdateLabelAdapter();
-			eObject.eAdapters().add(updateLabelAdapter);
-		}
 		orderElementControl.refreshInput();
 		updateLabel();
 	}
@@ -172,6 +167,22 @@ public class StatePropertySection extends AbstractEditorPropertySection
 		}
 	}
 
+	@Override
+	protected void setEObject(EObject object) {
+		if (getEObject() != null)
+			getEObject().eAdapters().remove(updateLabelAdapter);
+		super.setEObject(object);
+		getEObject().eAdapters().add(updateLabelAdapter);
+	}
+
+	@Override
+	public void dispose() {
+		if (getEObject() != null) {
+			getEObject().eAdapters().remove(updateLabelAdapter);
+		}
+		super.dispose();
+	}
+
 	@Override
 	public EObject getEObject() {
 		return super.getEObject();
@@ -196,7 +207,8 @@ public class StatePropertySection extends AbstractEditorPropertySection
 							new SetRequest(
 									eObject,
 									SGraphPackage.Literals.STATE__SUBSTATECHART_ID,
-									selectedSubmachine.toString()));
+									selectedSubmachine != null ? selectedSubmachine
+											.toString() : null));
 					try {
 						OperationHistoryFactory.getOperationHistory().execute(
 								command, new NullProgressMonitor(), null);

+ 16 - 16
plugins/org.yakindu.sct.ui.editor/src/org/yakindu/sct/ui/editor/propertysheets/StatechartPropertySection.java

@@ -22,7 +22,6 @@ import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Label;
@@ -41,22 +40,30 @@ import de.itemis.xtext.utils.jface.viewers.context.CloningBasedFakeContextResour
  * @author andreas muelder - Initial contribution and API
  * 
  */
-public class StatechartPropertySection extends AbstractEditorPropertySection
-		implements ISourceObjectCallback {
+public class StatechartPropertySection extends
+		AbstractTwoColumnEditorPropertySection implements ISourceObjectCallback {
 
 	private Control textControl;
 	private Text txtName;
 	private OrderElementControl orderElementControl;
 
-	public void createControls(Composite parent) {
-		parent.setLayout(new FillLayout());
-		Composite leftColumn = getToolkit().createComposite(parent);
-		leftColumn.setLayout(createBodyLayout());
-		Composite rightColumn = getToolkit().createComposite(parent);
-		rightColumn.setLayout(createBodyLayout());
+	@Override
+	protected void createLeftColumnControls(Composite leftColumn) {
 		createSpecificationControl(leftColumn);
+	}
+
+	@Override
+	protected void createRightColumnControls(Composite rightColumn) {
 		createNameControl(rightColumn);
 		createRegionsControl(rightColumn);
+
+	}
+
+	private void createNameControl(Composite parent) {
+		Label lblName = getToolkit().createLabel(parent, "Statechart Name: ");
+		txtName = getToolkit().createText(parent, "");
+		GridDataFactory.fillDefaults().applyTo(txtName);
+		GridDataFactory.fillDefaults().applyTo(lblName);
 	}
 
 	private void createRegionsControl(Composite rightColumn) {
@@ -68,13 +75,6 @@ public class StatechartPropertySection extends AbstractEditorPropertySection
 				.applyTo(orderElementControl);
 	}
 
-	private void createNameControl(Composite parent) {
-		Label lblName = getToolkit().createLabel(parent, "Statechart Name: ");
-		txtName = getToolkit().createText(parent, "");
-		GridDataFactory.fillDefaults().applyTo(txtName);
-		GridDataFactory.fillDefaults().applyTo(lblName);
-	}
-
 	private void createSpecificationControl(Composite parent) {
 		Injector injector = getInjector(SemanticTarget.StatechartSpecification);
 		if (injector != null) {