org.simantics.diagram.ontology,
org.eclipse.e4.core.services,
org.simantics.district.network.ontology;bundle-version="1.0.0",
- org.simantics.layer0.utils
+ org.simantics.layer0.utils,
+ org.eclipse.nebula.widgets.tablecombo
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: Semantum oy
import org.simantics.ui.selection.AnyResource;
import org.simantics.ui.selection.AnyVariable;
import org.simantics.ui.selection.WorkbenchSelectionContentType;
+import org.simantics.utils.ui.color.Color;
public class ElementSelectionTools {
}
}
+ public static float[] colorToLiteral(Color color) {
+ // BGRA float values out
+ return new float[] {
+ (float)color.getB() / 255,
+ (float)color.getG() / 255,
+ (float)color.getR() / 255,
+ 1.f,
+ };
+ }
+
+ public static Color literalToColor(float[] color) {
+ // BGRA float values in
+ return new Color((int) (color[2] * 255), (int) (color[1] * 255), (int) (color[0] * 255));
+ }
+
}
import java.util.Collection;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.TreeViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.Table;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.procedure.adapter.SyncListenerAdapter;
private static final Logger LOGGER = LoggerFactory.getLogger(ElementSelectorTableUI.class);
- private TreeViewer viewer;
+ private TableViewer viewer;
private ElementSelectionView view;
+ private ResourceManager resourceManager;
+
public ElementSelectorTableUI(Composite parent, int style, ElementSelectionView view) {
super(parent, style);
+
+ resourceManager = new LocalResourceManager(JFaceResources.getResources(), this);
+
this.view = view;
parent.setLayout(new FillLayout());
configureTable();
}
- public Tree getTree() {
- return viewer.getTree();
+ public Table getTable() {
+ return viewer.getTable();
}
public ElementSelector getSelectedItem() {
return selection != null ? (ElementSelector) selection.getFirstElement() : null;
}
- private TreeViewer createViewer() {
- return new TreeViewer(this, SWT.FULL_SELECTION);
+ private TableViewer createViewer() {
+ return new TableViewer(this, SWT.FULL_SELECTION | SWT.SINGLE);
}
private void configureTable() {
- Tree table = viewer.getTree();
+ Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
}
private void setContentProvider() {
- viewer.setContentProvider(new ITreeContentProvider() {
- @Override
- public boolean hasChildren(Object element) {
- return false;
- }
-
- @Override
- public Object getParent(Object element) {
- return null;
- }
-
+ viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
if (inputElement == null || !(inputElement instanceof Collection))
return ((Collection<?>)inputElement).toArray();
}
-
- @Override
- public Object[] getChildren(Object parentElement) {
- return null;
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- ITreeContentProvider.super.inputChanged(viewer, oldInput, newInput);
- }
});
}
- private TreeViewerColumn createNameColumn() {
- TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
+ private TableViewerColumn createNameColumn() {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText("Name");
column.getColumn().setWidth(200);
column.getColumn().setResizable(true);
@Override
public String getText(Object element) {
ElementSelector selector = (ElementSelector) element;
- return selector.getName();
+ return " " + selector.getName();
}
@Override
public Image getImage(Object element) {
- return null;
+ ElementSelector selector = (ElementSelector) element;
+ float[] color = selector.getColor();
+ if (color == null)
+ return null;
+
+ RGB rgb = ElementSelectionTools.literalToColor(color).getRgb();
+
+ PaletteData paletteData = new PaletteData(new RGB[] { new RGB(255, 255, 255), rgb });
+
+ // Create image with a colored horizontal bar
+ // TODO: Indicate line width
+ Image image = resourceManager.createImage(ImageDescriptor.createFromImageDataProvider(zoom -> {
+ int height = 8 * zoom / 100;
+ int width = 40 * zoom / 100;
+ ImageData imageData = new ImageData(width, height, 1, paletteData);
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ imageData.setPixel(x, y, 1);
+ }
+ }
+
+ return imageData;
+ }));
+
+ return image;
}
});
return column;
}
- private TreeViewerColumn createQueryColumn() {
- TreeViewerColumn column = new TreeViewerColumn(viewer, SWT.NONE);
+ private TableViewerColumn createQueryColumn() {
+ TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText("Query");
column.getColumn().setWidth(600);
column.getColumn().setResizable(true);
ElementSelector selector = (ElementSelector) element;
return selector.getExpression();
}
-
- @Override
- public Image getImage(Object element) {
- return null;
- }
});
return column;
}
private final class DoubleClickListener implements IDoubleClickListener {
@Override
public void doubleClick(DoubleClickEvent event) {
- TreeSelection selection = (TreeSelection) event.getViewer().getSelection();
+ IStructuredSelection selection = (IStructuredSelection) event.getViewer().getSelection();
Display display = event.getViewer().getControl().getDisplay();
ElementSelector query = (ElementSelector) selection.getFirstElement();
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceLocator;
+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.structural.stubs.StructuralResource2;
import org.simantics.utils.datastructures.Arrays;
import org.simantics.utils.datastructures.Pair;
+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
@PostConstruct
public void createPartControl(Composite parent, EMenuService menuService) {
table = new ElementSelectorTableUI(parent, SWT.BORDER, this);
- if (!(menuService.registerContextMenu(this.table.getTree(), POPUP_ID)))
+ if (!(menuService.registerContextMenu(this.table.getTable(), POPUP_ID)))
LOGGER.warn("Could not register context menu {}", POPUP_ID);
}
org.junit,
org.simantics,
org.simantics.structural.ontology,
- org.simantics.modeling.ontology
+ org.simantics.modeling.ontology,
+ org.simantics.g2d.ontology;bundle-version="1.1.0"
Export-Package: org.simantics.district.selection
DIA = <http://www.simantics.org/Diagram-2.2>
DNR = <http://www.simantics.org/DistrictNetworkRoutes-1.0>
REG = <http://www.simantics.org/DistrictDiagramRegions-1.0>
+G2D = <http://www.simantics.org/G2D-1.1>
ES = <http://www.simantics.org/ElementSelection-1.0> : L0.Ontology
@L0.new
>-- ES.Selection.HasGenerator --> ES.Generator <R L0.HasProperty : L0.FunctionalRelation
>-- ES.Selection.HasCondition --> ES.Condition <R L0.HasProperty : L0.FunctionalRelation
>-- ES.Selection.HasSelector --> ES.Selector <R L0.HasProperty : L0.FunctionalRelation
+
+ >-- ES.Selection.HasHighlightColor --> G2D.Color <R G2D.HasColor : L0.FunctionalRelation
+ >-- ES.Selection.HasLineWidth --> L0.Float <R G2D.HasStrokeWidth : L0.FunctionalRelation
+
@L0.singleProperty ES.Selection.HasGenerator
@L0.singleProperty ES.Selection.HasCondition
@L0.singleProperty ES.Selection.HasSelector
+
+ @L0.optionalProperty ES.Selection.HasHighlightColor
+ @L0.optionalProperty ES.Selection.HasLineWidth
ES.Generator <T L0.Entity
ES.Condition <T L0.Entity
public final Resource Selection_HasCondition_Inverse;
public final Resource Selection_HasGenerator;
public final Resource Selection_HasGenerator_Inverse;
+ public final Resource Selection_HasHighlightColor;
+ public final Resource Selection_HasHighlightColor_Inverse;
+ public final Resource Selection_HasLineWidth;
+ public final Resource Selection_HasLineWidth_Inverse;
public final Resource Selection_HasSelector;
public final Resource Selection_HasSelector_Inverse;
public final Resource Selector;
public static final String Selection_HasCondition_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasCondition/Inverse";
public static final String Selection_HasGenerator = "http://www.simantics.org/ElementSelection-1.0/Selection/HasGenerator";
public static final String Selection_HasGenerator_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasGenerator/Inverse";
+ public static final String Selection_HasHighlightColor = "http://www.simantics.org/ElementSelection-1.0/Selection/HasHighlightColor";
+ public static final String Selection_HasHighlightColor_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasHighlightColor/Inverse";
+ public static final String Selection_HasLineWidth = "http://www.simantics.org/ElementSelection-1.0/Selection/HasLineWidth";
+ public static final String Selection_HasLineWidth_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasLineWidth/Inverse";
public static final String Selection_HasSelector = "http://www.simantics.org/ElementSelection-1.0/Selection/HasSelector";
public static final String Selection_HasSelector_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasSelector/Inverse";
public static final String Selector = "http://www.simantics.org/ElementSelection-1.0/Selector";
Selection_HasCondition_Inverse = getResourceOrNull(graph, URIs.Selection_HasCondition_Inverse);
Selection_HasGenerator = getResourceOrNull(graph, URIs.Selection_HasGenerator);
Selection_HasGenerator_Inverse = getResourceOrNull(graph, URIs.Selection_HasGenerator_Inverse);
+ Selection_HasHighlightColor = getResourceOrNull(graph, URIs.Selection_HasHighlightColor);
+ Selection_HasHighlightColor_Inverse = getResourceOrNull(graph, URIs.Selection_HasHighlightColor_Inverse);
+ Selection_HasLineWidth = getResourceOrNull(graph, URIs.Selection_HasLineWidth);
+ Selection_HasLineWidth_Inverse = getResourceOrNull(graph, URIs.Selection_HasLineWidth_Inverse);
Selection_HasSelector = getResourceOrNull(graph, URIs.Selection_HasSelector);
Selection_HasSelector_Inverse = getResourceOrNull(graph, URIs.Selection_HasSelector_Inverse);
Selector = getResourceOrNull(graph, URIs.Selector);
Selector selector;
Condition condition;
+ private float[] color;
+
static Logger LOG = LoggerFactory.getLogger(ElementSelector.class);
static ElementSelectionResource ES;
try {
this.name = graph.getRelatedValue(resource, L0.HasLabel);
this.expression = getExpression(graph, resource);
+
+ float[] color = graph.getPossibleRelatedValue(resource, ES.Selection_HasHighlightColor);
+ this.color = color;
} catch (DatabaseException e) {
LOG.error("Error reading element selector", e);
throw e;
public Condition getCondition() {
return condition;
}
+
+ /**
+ * Get the selection highlight color as a four element BGRA array.
+ */
+ public float[] getColor() {
+ return color;
+ }
/**
*