]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.processeditor/src/org/simantics/processeditor/dialogs/LibraryComponentDialog.java
Removing ancient 3d framework
[simantics/3d.git] / org.simantics.processeditor / src / org / simantics / processeditor / dialogs / LibraryComponentDialog.java
diff --git a/org.simantics.processeditor/src/org/simantics/processeditor/dialogs/LibraryComponentDialog.java b/org.simantics.processeditor/src/org/simantics/processeditor/dialogs/LibraryComponentDialog.java
deleted file mode 100644 (file)
index c7df9e1..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.dialogs;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Stack;\r
-\r
-import org.eclipse.jface.dialogs.Dialog;\r
-import org.eclipse.jface.dialogs.IDialogConstants;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.List;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.simantics.db.Graph;\r
-import org.simantics.db.GraphRequestAdapter;\r
-import org.simantics.db.GraphRequestStatus;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.layer0.utils.EntityFactory;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.processeditor.ProcessResource;\r
-import org.simantics.proconf.ui.ProConfUI;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-\r
-\r
-public class LibraryComponentDialog extends Dialog{ \r
-       \r
-        private List typeList;\r
-     private Resource selectedType = null;\r
-     private Session session;\r
-     private String title;\r
-     \r
-     private Resource primaryType;\r
-     private Collection<Resource> requiredTypes = new ArrayList<Resource>();\r
-     private Collection<Resource> filteredTypes = new ArrayList<Resource>();\r
-     \r
-     public LibraryComponentDialog(Shell shell, Session session, Resource primaryType, String title) {\r
-        super(shell);\r
-        assert(title != null);\r
-        this.session = session;\r
-        this.title = title;\r
-        this.primaryType = primaryType;\r
-     }\r
-     \r
-     \r
-     protected void setFilter(Collection<Resource> filter) {\r
-        this.filteredTypes = filter;\r
-     }\r
-     \r
-     protected void setRequired(Collection<Resource> required) {\r
-        this.requiredTypes = required;\r
-     }\r
-     \r
-     \r
-     @Override\r
-     protected void configureShell(Shell newShell) {\r
-         \r
-         super.configureShell(newShell);\r
-         newShell.setText(title);\r
-     }\r
-\r
-     public Resource getComboValue() {\r
-         return selectedType;\r
-     }\r
-     \r
-     protected Control createDialogArea(Composite parent) {\r
-         Composite composite = (Composite) super.createDialogArea(parent);\r
-         \r
-         Label label = new Label(composite, SWT.WRAP);\r
-         label.setText("Select Component");\r
-         GridData data = new GridData(GridData.GRAB_HORIZONTAL\r
-                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
-                 | GridData.VERTICAL_ALIGN_CENTER);\r
-         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
-         label.setLayoutData(data);\r
-         label.setFont(parent.getFont());\r
-         // TODO : list populating is done in random order; change to alphabetic\r
-         typeList = new List(composite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY | SWT.V_SCROLL);\r
-         typeList.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));\r
-         \r
-         typeList.addSelectionListener(new SelectionListener() {\r
-             public void widgetSelected(SelectionEvent e) {\r
-                 String key = typeList.getItem(typeList.getSelectionIndex());\r
-                 selectedType = (Resource) typeList.getData(key);\r
-             }\r
-             public void widgetDefaultSelected(SelectionEvent e) {\r
-             }\r
-         });\r
-         getShell().setText(title + " loading...");\r
-         session.asyncRead(new GraphRequestAdapter() {\r
-               @Override\r
-               public GraphRequestStatus perform(Graph g) throws Exception {\r
-                       loadComponents(g);\r
-                       return GraphRequestStatus.transactionComplete();\r
-               }\r
-               \r
-               @Override\r
-               public void requestCompleted(GraphRequestStatus status) {\r
-                       getDialogArea().getDisplay().asyncExec(new Runnable() {\r
-                               @Override\r
-                               public void run() {\r
-                                       getShell().setText(title);\r
-                                       if (selectedType == null) {\r
-                                               if (typeList.getItemCount() > 0) {\r
-                                                       typeList.select(0);\r
-                                       selectedType = (Resource)typeList.getData(typeList.getItem(0));\r
-                                               }\r
-                           }\r
-                               }\r
-                               \r
-                       });\r
-               }\r
-         });\r
-\r
-         GridData data2 = new GridData(GridData.GRAB_HORIZONTAL\r
-                 | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL\r
-                 | GridData.VERTICAL_ALIGN_FILL);\r
-         data2.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);\r
-         data2.heightHint = 200;\r
-         typeList.setLayoutData(data2);\r
-         typeList.setFont(parent.getFont());\r
-         \r
-         typeList.showSelection();\r
-         \r
-         applyDialogFont(composite);\r
-         return composite;\r
-     }\r
-     \r
-     private void loadComponents(Graph g) {\r
-               Resource projectResource = ProConfUI.getProject().getResource();\r
-               Stack<Resource> handling = new Stack<Resource>();\r
-               handling.push(projectResource);\r
-               \r
-               // this is just a hack to get equipment defined in ontologies\r
-               Resource projectsLib = g.getObjects(projectResource, g.getBuiltins().PartOf).iterator().next();\r
-               Collection<Resource> projects = g.getObjects(projectsLib, g.getBuiltins().ConsistsOf);\r
-               Resource typeSystemProject = null;\r
-               for (Resource project : projects) {\r
-                       IEntity ent = EntityFactory.create(g,project);\r
-                       String name = ent.getName();\r
-                       if(name.equals("Type System Project")) {\r
-                               typeSystemProject = project;\r
-                               break;\r
-                       }\r
-               }\r
-               Collection<Resource> ontologies = g.getObjects(typeSystemProject, g.getBuiltins().ConsistsOf);\r
-               for (Resource ontology : ontologies) {\r
-                       if(g.isInstanceOf(ontology, g.getBuiltins().Ontology))\r
-                               handling.add(ontology);\r
-               }\r
-               \r
-               while (!handling.isEmpty()) {\r
-                       final Resource node = handling.pop();\r
-                       if (g.isInstanceOf(node,primaryType)) {\r
-                               IEntity equipment = EntityFactory.create(g, node);\r
-                               Collection<IEntity> graphics = equipment\r
-                                               .getRelatedObjects(ProcessResource.plant3Dresource.HasGraphics);\r
-                               if (graphics.size() != 1) {\r
-                                       ErrorLogger.defaultLogError("Equipment "\r
-                                                       + equipment.getName() + " has " + graphics.size()\r
-                                                       + " + graphical representation!", null);\r
-                               } else {\r
-                                       boolean add = true;\r
-                                       for (Resource r : requiredTypes) {\r
-                                               if (!equipment.isInstanceOf(r)) {\r
-                                                       add = false;\r
-                                                       break;\r
-                                               }\r
-                                       }\r
-                                       if (add) {\r
-                                               for (Resource r : filteredTypes) {\r
-                                                       if (equipment.isInstanceOf(r)) {\r
-                                                               add = false;\r
-                                                               break;\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                                       if (add) {\r
-                                               final String name = equipment.getName();\r
-                                               getDialogArea().getDisplay().asyncExec(new Runnable() {\r
-                                                       public void run() {\r
-                                                               // List won't work with two ore more same names.\r
-                                                               if (typeList.getData(name)!= null) {\r
-                                                                       String n = new String(name);\r
-                                                                       int i = 1;\r
-                                                                       while (true) {\r
-                                                                               n = name +"("+i+")";\r
-                                                                               if (typeList.getData(n)== null) {\r
-                                                                                       typeList.add(n);\r
-                                                                                       typeList.setData(n, node);\r
-                                                                                       break;\r
-                                                                               }\r
-                                                                       }\r
-                                                               } else {\r
-                                                                       typeList.add(name);\r
-                                                                       typeList.setData(name, node);\r
-                                                               }\r
-                                                       }\r
-                                               });\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               handling.addAll(g.getObjects(node,\r
-                                               ProcessResource.builtins.ConsistsOf));\r
-                       }\r
-\r
-               }\r
-               \r
-       }\r
-       \r
-\r
-}\r