]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
Show an error dialog when attempting to insert a too long component
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / actions / AddComponentAction.java
index d9ee9d70849188f7f50e7ba0bc2b58513609c3ac..9b3d90835e14a3961f5c9af0c48fd7ead86417dc 100644 (file)
@@ -6,6 +6,7 @@ import java.awt.event.MouseWheelEvent;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.resource.ResourceLocator;
 import org.eclipse.swt.widgets.Display;
 import org.simantics.db.Resource;
@@ -50,6 +51,8 @@ public class AddComponentAction extends vtkSwtAction {
        
        private String libUri;
        
+       private double lengthFactor = 1.0;
+       
        public AddComponentAction(InteractiveVtkComposite panel, P3DRootNode root, String libUri) {
                super(panel);
                this.root = root;
@@ -60,6 +63,10 @@ public class AddComponentAction extends vtkSwtAction {
                this.libUri = libUri;
        }
        
+       public void setLengthFactor(double lengthFactor) {
+               this.lengthFactor = lengthFactor;
+       }
+
        public void setComponent(PipelineComponent component) {
                this.component = component;
                
@@ -97,6 +104,7 @@ public class AddComponentAction extends vtkSwtAction {
                
                // Set list of already reserved component names
                dialog.addUsedNames(ComponentUtils.getPipelineComponentNames(root));
+               dialog.setLengthFactor(lengthFactor);
                
                if (dialog.open() == ComponentSelectionDialog.CANCEL)
                        return;
@@ -180,6 +188,11 @@ public class AddComponentAction extends vtkSwtAction {
        
        public void doInsert(PositionType position) {
                try  {
+                       if (position == PositionType.SPLIT && length != null && length > component.getControlPoint().getLength()) {
+                               MessageDialog.openError(panel.getComponent().getShell(), "Error", "There is no room for a component of length " + length * lengthFactor + " units");
+                               return;
+                       }
+                       
                        InsertInstruction inst = new InsertInstruction();
                        inst.typeUri = toAdd.getUri();
                        inst.name = name;