import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.window.Window;
+import org.eclipse.nebula.widgets.tablecombo.TableCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;
import org.simantics.Simantics;
+import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
import org.simantics.db.layer0.request.PropertyInfoRequest;
import org.simantics.db.layer0.util.Layer0Utils;
import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.stubs.G2DResource;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.district.region.ontology.DiagramRegionsResource;
import org.simantics.district.route.ontology.RouteResource;
import org.simantics.district.selection.ElementSelector.RegionCondition;
import org.simantics.district.selection.ElementSelector.RouteCondition;
import org.simantics.district.selection.ElementSelector.Selector;
+import org.simantics.district.selection.ui.ElementSelectionTools;
import org.simantics.layer0.Layer0;
import org.simantics.layer0.utils.direct.GraphUtils;
import org.simantics.modeling.ModelingResources;
import org.simantics.utils.datastructures.Arrays;
import org.simantics.utils.datastructures.Pair;
import org.simantics.utils.ui.BundleUtils;
+import org.simantics.utils.ui.color.Color;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private String name;
private Text nameField;
+ private Color color;
+ private TableCombo colorCombo;
+
private Resource diagram;
private Combo diagramField;
// Called to read values from controls into conditions
Updater updater = NULL_UPDATE;
-
@Inject
public EditSelectorDialog(Shell shell, ElementSelector elementSelector, Collection<Resource> currentSelection) {
super(shell);
condition = null;
if (elementSelector != null) {
+ float[] color = elementSelector.getColor();
+ if (color != null) {
+ this.color = ElementSelectionTools.literalToColor(color);
+ }
+
Generator generator = elementSelector.getGenerator();
if (generator instanceof ModelGenerator) {
generatorIndex = 0;
throw new ValidationException("Please enter a name");
}
+ {
+ int index = colorCombo.getSelectionIndex();
+ if (index >= 0) {
+ color = new Color(colorCombo.getTable().getItem(index).getBackground().getRGB());
+ }
+ }
+
componentType = componentTypes.get(componentTypeField.getSelectionIndex());
selectorIndex = selectorField.getSelectionIndex();
graph.claimLiteral(selection, L0.HasLabel, L0.String, name);
graph.claim(selection, L0.PartOf, lib);
+ if (color != null) {
+ float[] value = ElementSelectionTools.colorToLiteral(color);
+ graph.claimLiteral(selection, ES.Selection_HasHighlightColor, G2DResource.getInstance(graph).Color, value, Bindings.FLOAT_ARRAY);
+ }
+
// Generator
Resource generator = graph.newResource();
Resource generatorType;
nameField.setText(name);
GridDataFactory.swtDefaults().hint(200, SWT.DEFAULT).applyTo(nameField);
+ // Highlight style
+ Label label = new Label(content, SWT.NONE);
+ GridDataFactory.swtDefaults().applyTo(label);
+ label.setText("Highlight color");
+
+ colorCombo = new TableCombo(content, SWT.BORDER | SWT.READ_ONLY);
+ GridDataFactory.swtDefaults().hint(80, SWT.DEFAULT).applyTo(colorCombo);
+ Table colorTable = colorCombo.getTable();
+ colorCombo.getTextControl().setEnabled(false);
+ Display display = getShell().getDisplay();
+ colorTable.setFont(display.getSystemFont());
+ createColorItem(colorTable, "Red", SWT.COLOR_RED);
+ createColorItem(colorTable, "Green", SWT.COLOR_GREEN);
+ createColorItem(colorTable, "Blue", SWT.COLOR_BLUE);
+ createColorItem(colorTable, "Yellow", SWT.COLOR_YELLOW);
+ createColorItem(colorTable, "Cyan", SWT.COLOR_CYAN);
+ createColorItem(colorTable, "Magenta", SWT.COLOR_MAGENTA);
+ TableItem other = new TableItem(colorTable, SWT.NONE);
+ other.setText("Other...");
+
+ if (color != null) {
+ int i;
+ for (i = 0; i < 6; i++) {
+ if (colorTable.getItem(i).getBackground().getRGB().equals(color.getRgb())) {
+ colorCombo.select(i);
+ break;
+ }
+ }
+
+ if (i == 6) {
+ other.setBackground(resourceManager.createColor(color.getRgb()));
+ colorCombo.select(6);
+ }
+ }
+
+ colorCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = colorCombo.getSelectionIndex();
+ if (index == 6) {
+ org.simantics.utils.ui.color.ColorDialog colorDialog = new org.simantics.utils.ui.workbench.dialogs.ColorDialog(getParentShell());
+ int result = colorDialog.open();
+ if (result == Window.OK) {
+ other.setBackground(resourceManager.createColor(colorDialog.getColor().getRgb()));
+ colorCombo.clearSelection();
+ colorCombo.select(6);
+ colorTable.redraw();
+ }
+ }
+ }
+ });
+
// Selector
Label selectorLabel = new Label(content, SWT.NONE);
selectorLabel.setText("Select");
sourceField.select(generatorIndex);
// Condition
- Label label = new Label(content, SWT.NONE);
+ label = new Label(content, SWT.NONE);
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(label);
label.setText("where");
conditionPanel = new Composite(content, SWT.NONE);
- GridDataFactory.swtDefaults().span(1, 2).minSize(400, SWT.DEFAULT).grab(true, false).applyTo(conditionPanel);
+ GridDataFactory.swtDefaults().minSize(400, SWT.DEFAULT).grab(true, false).applyTo(conditionPanel);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(conditionPanel);
updater = updateConditionPanel();
return content;
}
+
+ private TableItem createColorItem(Table colorTable, String name, int color) {
+ TableItem item = new TableItem(colorTable, SWT.BORDER);
+ item.setText(name);
+ item.setBackground(colorTable.getDisplay().getSystemColor(color));
+ return item;
+ }
private Updater updateConditionPanel() {
// Erase contents