X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FCreateSharedOntologyDialog.java;h=6fd72777268e3ace9f1543d0c5e1c9431734e44c;hp=f4bd630da417b7d95ef2d8a86ac727a0fc44ebf9;hb=3a10ce856f7124f83cf03d6e7f7576da237a7cbb;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/CreateSharedOntologyDialog.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/CreateSharedOntologyDialog.java index f4bd630da..6fd727772 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/CreateSharedOntologyDialog.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/CreateSharedOntologyDialog.java @@ -1,146 +1,146 @@ -/******************************************************************************* - * Copyright (c) 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * 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: - * Semantum Oy - initial API and implementation - *******************************************************************************/ -package org.simantics.modeling; - -import java.util.Map; - -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.layout.GridLayoutFactory; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.common.uri.UnescapedChildMapOfResource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3; -import org.simantics.utils.datastructures.Pair; - -public class CreateSharedOntologyDialog extends ResourceSelectionDialog3 { - - private String name; - private Text t; - - public CreateSharedOntologyDialog(Shell shell, - Map> parameter, String title) { - super(shell, parameter, title); - this.name = ""; - } - - @Override - protected IDialogSettings getBaseDialogSettings() { - return null; - } - - @Override - protected Control createExtendedContentArea(Composite parent) { - Composite c = new Composite(parent, SWT.NONE); - GridDataFactory.fillDefaults().grab(true, false).applyTo(c); - GridLayoutFactory.swtDefaults().numColumns(2).applyTo(c); - Label l = new Label(c, SWT.NONE); - l.setText("Enter URI for the shared library: http://"); - GridDataFactory.fillDefaults().grab(false, false).applyTo(l); - t = new Text(c, SWT.BORDER); - t.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - name = t.getText(); - validatePage(); - } - }); - GridDataFactory.fillDefaults().grab(true, false).applyTo(t); - validatePage(); - return super.createExtendedContentArea(parent); - } - - @Override - public void create() { - super.create(); - t.setFocus(); - } - - @Override - protected void handleSelected(StructuredSelection selection) { - super.handleSelected(selection); - validatePage(); - } - - protected void validatePage() { - StructuredSelection selection = getSelectedItems(); - String error = validateName(name); - if (error != null) { - updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error)); - } else if (selection.isEmpty()) { - updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "No Library selected")); - } else { - // Validate that the name is not in use. - Resource library = (Resource) selection.getFirstElement(); - try { - Map children = Simantics.sync(new UnescapedChildMapOfResource(library)); - if (children.containsKey(name)) { - updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Name is already in use.")); - } else { - updateStatus(new Status(Status.OK, PlatformUI.PLUGIN_ID, "")); - } - } catch (DatabaseException e) { - updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Failed to check validity of name. See error log.", e)); - } - } - } - - protected String validateName(final String name) { - - try { - boolean inUse = Simantics.sync(new UniqueRead() { - - @Override - public Boolean perform(ReadGraph graph) throws DatabaseException { - Resource r = graph.getPossibleResource("http://" + name + "@A"); - return r != null; - } - - }); - if(inUse) return "Shared Library exists already"; - } catch (DatabaseException e) { - return e.getMessage(); - } - - if (name.trim().isEmpty()) - return "Name cannot be empty"; - if (name.startsWith(".")) - return "Name cannot begin with a dot"; - if (name.startsWith("/")) - return "Name cannot begin with a slash"; - if (name.contains("//")) - return "Successive slashes are not allowed"; - if (name.endsWith("/")) - return "Name cannot end with slash"; - return null; - } - - public String getName() { - return name; - } - +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling; + +import java.util.Map; + +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.ui.workbench.dialogs.ResourceSelectionDialog3; +import org.simantics.utils.datastructures.Pair; + +public class CreateSharedOntologyDialog extends ResourceSelectionDialog3 { + + private String name; + private Text t; + + public CreateSharedOntologyDialog(Shell shell, + Map> parameter, String title) { + super(shell, parameter, title); + this.name = ""; + } + + @Override + protected IDialogSettings getBaseDialogSettings() { + return null; + } + + @Override + protected Control createExtendedContentArea(Composite parent) { + Composite c = new Composite(parent, SWT.NONE); + GridDataFactory.fillDefaults().grab(true, false).applyTo(c); + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(c); + Label l = new Label(c, SWT.NONE); + l.setText("Enter URI for the shared library: http://"); + GridDataFactory.fillDefaults().grab(false, false).applyTo(l); + t = new Text(c, SWT.BORDER); + t.addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + name = t.getText(); + validatePage(); + } + }); + GridDataFactory.fillDefaults().grab(true, false).applyTo(t); + validatePage(); + return super.createExtendedContentArea(parent); + } + + @Override + public void create() { + super.create(); + t.setFocus(); + } + + @Override + protected void handleSelected(StructuredSelection selection) { + super.handleSelected(selection); + validatePage(); + } + + protected void validatePage() { + StructuredSelection selection = getSelectedItems(); + String error = validateName(name); + if (error != null) { + updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, error)); + } else if (selection.isEmpty()) { + updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "No Library selected")); + } else { + // Validate that the name is not in use. + Resource library = (Resource) selection.getFirstElement(); + try { + Map children = Simantics.sync(new UnescapedChildMapOfResource(library)); + if (children.containsKey(name)) { + updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Name is already in use.")); + } else { + updateStatus(new Status(Status.OK, PlatformUI.PLUGIN_ID, "")); + } + } catch (DatabaseException e) { + updateStatus(new Status(Status.ERROR, PlatformUI.PLUGIN_ID, "Failed to check validity of name. See error log.", e)); + } + } + } + + protected String validateName(final String name) { + + try { + boolean inUse = Simantics.sync(new UniqueRead() { + + @Override + public Boolean perform(ReadGraph graph) throws DatabaseException { + Resource r = graph.getPossibleResource("http://" + name + "@A"); + return r != null; + } + + }); + if(inUse) return "Shared Library exists already"; + } catch (DatabaseException e) { + return e.getMessage(); + } + + if (name.trim().isEmpty()) + return "Name cannot be empty"; + if (name.startsWith(".")) + return "Name cannot begin with a dot"; + if (name.startsWith("/")) + return "Name cannot begin with a slash"; + if (name.contains("//")) + return "Successive slashes are not allowed"; + if (name.endsWith("/")) + return "Name cannot end with slash"; + return null; + } + + public String getName() { + return name; + } + } \ No newline at end of file