- private static class DefaultMappingsDialog extends SelectionStatusDialog {
-
- private Combo vertexMappingCombo;
- private Combo edgeMappingCombo;
- private Combo crsCombo;
- private Composite composite;
-
- private Resource configuration;
- private Map<String, Resource> vertexMappings = new HashMap<>();
- private Map<String, Resource> edgeMappings = new HashMap<>();
- private Map<String, Resource> composites = new HashMap<>();
- private Map<String, Resource> crss = new HashMap<>();
-
- private Resource defaultVertexMapping;
- private Resource defaultEdgeMapping;
- private Resource defaultCRS;
-
- private Combo compositeMappingCombo;
- private Combo componentMappingCombo;
-
- protected DefaultMappingsDialog(Shell parentShell, Resource configuration) {
- super(parentShell);
- this.configuration = configuration;
- setTitle("Select mappings for new DN diagram");
- }
-
- public Resource getDefaultVertexMapping() {
- return defaultVertexMapping;
- }
-
- public Resource getDefaultEdgeMapping() {
- return defaultEdgeMapping;
- }
-
- @Override
- protected Control createDialogArea(Composite parent) {
- composite = (Composite) super.createDialogArea(parent);
-
- createMappingsGroup(composite);
- createExistingCompositeGroup(composite);
- createCRSSettingsGroup(composite);
-
- // compute default values
- Simantics.getSession().asyncRequest(new ReadRequest() {
-
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
- Resource indexRoot = graph.sync(new IndexRoot(configuration));
- vertexMappings = getVertexMappings(graph, indexRoot);
- edgeMappings = getEdgeMappings(graph, indexRoot);
-
- composites = getComposites(graph, configuration);
-
- crss = getCRSs(graph, configuration);
-
- composite.getDisplay().asyncExec(() -> {
-
- vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()]));
- edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()]));
-
- crsCombo.setItems(crss.keySet().toArray(new String[crss.size()]));
-
- compositeMappingCombo.setItems(composites.keySet().toArray(new String[composites.size()]));
- vertexMappingCombo.select(0);
- edgeMappingCombo.select(0);
-
- crsCombo.select(0);
-
- if (!composites.isEmpty())
- compositeMappingCombo.select(0);
- });
-
- }
- });
- return composite;
- }
-
- protected Map<String, Resource> getComposites(ReadGraph graph, Resource element) throws DatabaseException {
- List<Resource> nonDistrictComposites = composites.values().stream().filter(comp -> {
- try {
- return !graph.isInstanceOf(comp, DistrictNetworkResource.getInstance(graph).Composite);
- } catch (ServiceException e1) {
- LOGGER.error("Could not check if composite " + comp + " is instanceOf DistrictNetwork.composite");
- return false;
- }
- }).collect(Collectors.toList());
- Map<String, Resource> result = new HashMap<>(nonDistrictComposites.size());
- Layer0 L0 = Layer0.getInstance(graph);
- nonDistrictComposites.forEach(mapping -> {
- try {
- String name = graph.getRelatedValue2(mapping, L0.HasName);
- result.put(name, mapping);
- } catch (DatabaseException e) {
- LOGGER.error("Could not read name of " + mapping, e);
- }
- });
- return result;
- }
-
- private void createMappingsGroup(Composite parent) {
- Group group= new Group(parent, SWT.NONE);
- group.setFont(parent.getFont());
- group.setText("Default mappings");
- GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
- group.setLayout(new GridLayout(1, false));
-
- Composite cmposite = new Composite(group, SWT.NONE);
- cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- cmposite.setLayout(new GridLayout(2, false));
-
- Label vertexMappingLabel = new Label(cmposite, SWT.NONE);
- vertexMappingLabel.setText("Default vertex mapping");
-
- vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo);
-
- Label edgeMappingLabel = new Label(cmposite, SWT.NONE);
- edgeMappingLabel.setText("Default edge mapping");
-
- edgeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(edgeMappingCombo);
- }
-
- private void createExistingCompositeGroup(Composite parent) {
- Group group= new Group(parent, SWT.NONE);
- group.setFont(parent.getFont());
- group.setText("Mapped composite");
- GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
- group.setLayout(new GridLayout(1, false));
-
- Composite cmposite = new Composite(group, SWT.NONE);
- cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- cmposite.setLayout(new GridLayout(2, false));
-
- Label compositeMappingLabel = new Label(cmposite, SWT.NONE);
- compositeMappingLabel.setText("Select composite");
-
- compositeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(compositeMappingCombo);
- compositeMappingCombo.addSelectionListener(new SelectionAdapter() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- super.widgetSelected(e);
- recalculateMappapleComponents();
- }
- });
-
- Label compojnentMappingLabel = new Label(cmposite, SWT.NONE);
- compojnentMappingLabel.setText("Select component");
-
- componentMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
- GridDataFactory.fillDefaults().grab(true, false).applyTo(componentMappingCombo);
- }
-
- protected void recalculateMappapleComponents() {
- Simantics.getSession().asyncRequest(new ReadRequest() {
-
- @Override
- public void run(ReadGraph graph) throws DatabaseException {
-
-
- composite.getDisplay().asyncExec(() -> {
-
- });
- }
- });
- }
-
- private void createCRSSettingsGroup(Composite parent) {
- Group group= new Group(parent, SWT.NONE);
- group.setFont(parent.getFont());
- group.setText("CRS settings");
- GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
- group.setLayout(new GridLayout(1, false));
-
- Composite cmposite = new Composite(group, SWT.NONE);
- cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
- cmposite.setLayout(new GridLayout(2, false));
-
- Label vertexMappingLabel = new Label(cmposite, SWT.NONE);
- vertexMappingLabel.setText("Default CRS");
-
- crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
- GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false);
- crsCombo.setLayoutData(textData);
- }
-
-
- @Override
- protected void computeResult() {
- defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex()));
- defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex()));
- defaultCRS = crss.get(crsCombo.getItem(crsCombo.getSelectionIndex()));
- }
-
- public Resource getCRS() {
- return defaultCRS;
- }
-
- }
-
- private static void queryInitialValuesAndCreateComposite(final Resource compositeType, final Resource target,