Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-04-02 15:57:32 +0000
committercletavernie2012-04-02 15:57:32 +0000
commitb19c128f861a85fcc1292a528dcf6fa6bb19e6ab (patch)
treec709637e2ce855661672a2b9e8f4778bf7dca0b5
parent3235733789ac89fc6ba6c1d709f64638034c07ad (diff)
downloadorg.eclipse.papyrus-b19c128f861a85fcc1292a528dcf6fa6bb19e6ab.tar.gz
org.eclipse.papyrus-b19c128f861a85fcc1292a528dcf6fa6bb19e6ab.tar.xz
org.eclipse.papyrus-b19c128f861a85fcc1292a528dcf6fa6bb19e6ab.zip
370797: [Theme] Papyrus should provide a support for CSS files on its diagrams
https://bugs.eclipse.org/bugs/show_bug.cgi?id=370797
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/StyleCreationDialog.java88
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java4
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java20
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/InputDialog.java10
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringEditor.java2
5 files changed, 106 insertions, 18 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/StyleCreationDialog.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/StyleCreationDialog.java
index 5a0eda76c54..3e5c7d8b8c6 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/StyleCreationDialog.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/StyleCreationDialog.java
@@ -14,6 +14,7 @@ package org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler;
import java.util.Map;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
@@ -43,6 +44,7 @@ import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
import org.eclipse.papyrus.infra.widgets.editors.StringFileSelector;
import org.eclipse.papyrus.infra.widgets.providers.StaticContentProvider;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.layout.GridData;
@@ -70,6 +72,8 @@ public class StyleCreationDialog extends TrayDialog {
private StyleSheet stylesheet;
+ private CLabel errorLabel;
+
/**
*
* @param shell
@@ -93,7 +97,7 @@ public class StyleCreationDialog extends TrayDialog {
Composite parent = getDialogArea();
CTabFolder tabFolder = new CTabFolder(parent, SWT.BORDER);
- tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
+ tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
CTabItem conditionsTab = new CTabItem(tabFolder, SWT.NONE);
CTabItem declarationsTab = new CTabItem(tabFolder, SWT.NONE);
@@ -128,10 +132,68 @@ public class StyleCreationDialog extends TrayDialog {
createDeclarations(declarationsContainer);
createStylesheet(stylesheetContainer);
+ updateButtons();
+
getShell().setText("New Style");
getShell().pack();
}
+ protected void updateButtons() {
+ //Resets the error message
+ setError(null);
+ getButton(IDialogConstants.OK_ID).setEnabled(isValid());
+ getDialogArea().layout();
+ }
+
+ protected boolean isValid() {
+ boolean result = true;
+
+ //There must be a stylesheet
+ if(getStylesheet() == null) {
+ setError("You must select a Stylesheet");
+ result = false;
+ }
+
+ //There must be at least one property declaration
+ boolean atLeastOneDeclaration = false;
+ for(Boolean value : declarations.values()) {
+ if(value) {
+ atLeastOneDeclaration = true;
+ break;
+ }
+ }
+
+ result = result && atLeastOneDeclaration;
+
+ if(!atLeastOneDeclaration) {
+ setError("There must be at least one property declaration");
+ }
+
+ return result;
+ }
+
+ protected void setError(String errorMessage) {
+ if(errorMessage == null && errorLabel != null) {
+ errorLabel.dispose();
+ errorLabel = null;
+ return;
+ }
+
+ if(errorMessage != null) {
+ if(errorLabel == null) {
+ errorLabel = new CLabel(getDialogArea(), SWT.WRAP);
+ errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
+ errorLabel.setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/error.gif"));
+ }
+
+ if(errorLabel.getText() != null && !errorLabel.getText().trim().equals("")) {
+ errorLabel.setText(errorLabel.getText() + "\n" + errorMessage);
+ } else {
+ errorLabel.setText(errorMessage);
+ }
+ }
+ }
+
protected void createConditions(Composite parent) {
parent.setLayout(new GridLayout(3, false));
@@ -206,7 +268,6 @@ public class StyleCreationDialog extends TrayDialog {
}
BooleanCheckbox checkbox = new BooleanCheckbox(parent, SWT.NONE, attributeLabel);
- checkbox.setValue(conditions.get(currentCondition));
checkbox.addCommitListener(new ICommitListener() {
@@ -227,7 +288,6 @@ public class StyleCreationDialog extends TrayDialog {
StringEditor styleNameEditor = new StringEditor(parent, SWT.NONE, "Style name:");
styleNameEditor.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 3, 1));
- // styleNameEditor.setToolTipText(label);
styleNameEditor.addCommitListener(new ICommitListener() {
public void commit(AbstractEditor editor) {
@@ -239,7 +299,6 @@ public class StyleCreationDialog extends TrayDialog {
protected void createDeclarations(Composite parent) {
parent.setLayout(new GridLayout(3, false));
- // parent.setLayout(new FillLayout());
Label declarationsLabel = new Label(parent, SWT.WRAP);
declarationsLabel.setText("Select the properties you want to set. Unchecked properties will keep their default value (Which might be inherited from another style).");
@@ -248,15 +307,21 @@ public class StyleCreationDialog extends TrayDialog {
for(Declaration declaration : declarations.keySet()) {
String label = declaration.getProperty() + ": " + getLabel(declaration.getExpression());
BooleanCheckbox checkbox = new BooleanCheckbox(parent, SWT.NONE, label);
- checkbox.setValue(declarations.get(declaration));
final Declaration currentDeclaration = declaration;
+
+ checkbox.setValue(declarations.get(currentDeclaration));
+
checkbox.addCommitListener(new ICommitListener() {
public void commit(AbstractEditor editor) {
- declarations.put(currentDeclaration, ((BooleanCheckbox)editor).getValue());
+ boolean value = ((BooleanCheckbox)editor).getValue();
+ declarations.put(currentDeclaration, value);
+ updateButtons();
}
});
+
+ checkbox.setValue(declarations.get(declaration));
}
}
@@ -275,9 +340,12 @@ public class StyleCreationDialog extends TrayDialog {
public void commit(AbstractEditor editor) {
String path = (String)((StringEditor)editor).getValue();
- StyleSheetReference stylesheetReference = StylesheetsFactory.eINSTANCE.createStyleSheetReference();
- stylesheetReference.setPath(path);
- stylesheet = stylesheetReference;
+ if(path != null && !"".equals(path)) {
+ StyleSheetReference stylesheetReference = StylesheetsFactory.eINSTANCE.createStyleSheetReference();
+ stylesheetReference.setPath(path);
+ stylesheet = stylesheetReference;
+ updateButtons();
+ }
}
});
@@ -297,6 +365,7 @@ public class StyleCreationDialog extends TrayDialog {
EmbeddedStyleSheet embeddedStylesheet = StylesheetsFactory.eINSTANCE.createEmbeddedStyleSheet();
embeddedStylesheet.setLabel(name);
stylesheet = embeddedStylesheet;
+ updateButtons();
}
});
@@ -315,6 +384,7 @@ public class StyleCreationDialog extends TrayDialog {
public void commit(AbstractEditor editor) {
StyleSheet value = (StyleSheet)((ReferenceDialog)editor).getValue();
stylesheet = value;
+ updateButtons();
}
});
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java
index fdd3b213355..182875424f4 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/AbstractEditor.java
@@ -36,6 +36,10 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
*
* @author Camille Letavernier
*/
+//FIXME: The composite widget hides access to the encapsulated widget(s).
+//Thus, it is not possible to add custom listeners on the editors
+//We should forward the listeners to the encapsulated (this.addListener(int, Listener) -> getMainWidget().addListener(int, Listener))
+//Problem: some widgets have more than one "main widget" (e.g. EnumRadio).
public abstract class AbstractEditor extends Composite {
/**
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
index 898929abc0e..579ca8ac489 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
@@ -27,7 +27,7 @@ import org.eclipse.swt.widgets.Composite;
*/
public class BooleanCheckbox extends AbstractValueEditor {
- private Button checkbox;
+ private final Button checkbox;
private AggregatedObservable aggregated;
@@ -61,19 +61,25 @@ public class BooleanCheckbox extends AbstractValueEditor {
super(parent);
checkbox = factory.createButton(this, label, SWT.CHECK | style);
- setCommitOnFocusLost(checkbox);
+ IObservableValue widgetObservable = WidgetProperties.selection().observe(checkbox);
+ setWidgetObservable(widgetObservable, true);
}
@Override
public void setModelObservable(IObservableValue modelProperty) {
- IObservableValue widgetObservable;
+ IObservableValue newWidgetObservable;
+
+ if(this.widgetObservable != null) {
+ this.widgetObservable.dispose();
+ }
+
if(modelProperty instanceof AggregatedObservable) {
this.aggregated = (AggregatedObservable)modelProperty;
- widgetObservable = new GrayedCheckboxObservableValue(checkbox, aggregated);
+ newWidgetObservable = new GrayedCheckboxObservableValue(checkbox, aggregated);
} else {
- widgetObservable = WidgetProperties.selection().observe(checkbox);
+ newWidgetObservable = WidgetProperties.selection().observe(checkbox);
}
- setWidgetObservable(widgetObservable, true);
+ setWidgetObservable(newWidgetObservable, true);
super.setModelObservable(modelProperty);
}
@@ -118,6 +124,6 @@ public class BooleanCheckbox extends AbstractValueEditor {
if(modelProperty != null) {
modelProperty.setValue(selected);
}
- checkbox.setSelection(selected);
+ widgetObservable.setValue(selected);
}
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/InputDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/InputDialog.java
index fceff6994b9..b4ebcb63fa3 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/InputDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/InputDialog.java
@@ -124,7 +124,15 @@ public class InputDialog extends SelectionDialog {
((StringCombo)editor).setValue(initialValue);
((StringCombo)editor).setContentProvider(contentProvider);
} else {
- editor = new StringEditor(getDialogArea(), SWT.BORDER);
+ editor = new StringEditor(getDialogArea(), SWT.BORDER) {
+
+ //FIXME: The StringEditor (Or one of its superclasses) should be responsible for forwarding this call
+ @Override
+ public void addKeyListener(KeyListener keyListener) {
+ super.text.addKeyListener(keyListener);
+ }
+ };
+
((StringEditor)editor).setValue(initialValue);
}
// input = new Text(getDialogArea(), SWT.BORDER);
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringEditor.java
index 613db74d505..9a27b75840f 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringEditor.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringEditor.java
@@ -42,7 +42,7 @@ public class StringEditor extends AbstractValueEditor implements KeyListener, Mo
/**
* The text box for editing this editor's value
*/
- protected Text text;
+ protected final Text text;
private int delay = 600;

Back to the top