X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fdialogs%2FLibraryComponentDialog.java;fp=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fdialogs%2FLibraryComponentDialog.java;h=0000000000000000000000000000000000000000;hb=6b6fcff5d6c326feef07ccf8401f97911778fffe;hp=c7df9e1294a5fdc297bef99572fefc3162b74c42;hpb=504c111db40d78f4913badddd126b283b5504dbb;p=simantics%2F3d.git 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 index c7df9e12..00000000 --- a/org.simantics.processeditor/src/org/simantics/processeditor/dialogs/LibraryComponentDialog.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.processeditor.dialogs; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Stack; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Shell; -import org.simantics.db.Graph; -import org.simantics.db.GraphRequestAdapter; -import org.simantics.db.GraphRequestStatus; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.layer0.utils.EntityFactory; -import org.simantics.layer0.utils.IEntity; -import org.simantics.processeditor.ProcessResource; -import org.simantics.proconf.ui.ProConfUI; -import org.simantics.utils.ui.ErrorLogger; - - -public class LibraryComponentDialog extends Dialog{ - - private List typeList; - private Resource selectedType = null; - private Session session; - private String title; - - private Resource primaryType; - private Collection requiredTypes = new ArrayList(); - private Collection filteredTypes = new ArrayList(); - - public LibraryComponentDialog(Shell shell, Session session, Resource primaryType, String title) { - super(shell); - assert(title != null); - this.session = session; - this.title = title; - this.primaryType = primaryType; - } - - - protected void setFilter(Collection filter) { - this.filteredTypes = filter; - } - - protected void setRequired(Collection required) { - this.requiredTypes = required; - } - - - @Override - protected void configureShell(Shell newShell) { - - super.configureShell(newShell); - newShell.setText(title); - } - - public Resource getComboValue() { - return selectedType; - } - - protected Control createDialogArea(Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); - - Label label = new Label(composite, SWT.WRAP); - label.setText("Select Component"); - GridData data = new GridData(GridData.GRAB_HORIZONTAL - | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_CENTER); - data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); - label.setLayoutData(data); - label.setFont(parent.getFont()); - // TODO : list populating is done in random order; change to alphabetic - typeList = new List(composite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY | SWT.V_SCROLL); - typeList.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); - - typeList.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - String key = typeList.getItem(typeList.getSelectionIndex()); - selectedType = (Resource) typeList.getData(key); - } - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - getShell().setText(title + " loading..."); - session.asyncRead(new GraphRequestAdapter() { - @Override - public GraphRequestStatus perform(Graph g) throws Exception { - loadComponents(g); - return GraphRequestStatus.transactionComplete(); - } - - @Override - public void requestCompleted(GraphRequestStatus status) { - getDialogArea().getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - getShell().setText(title); - if (selectedType == null) { - if (typeList.getItemCount() > 0) { - typeList.select(0); - selectedType = (Resource)typeList.getData(typeList.getItem(0)); - } - } - } - - }); - } - }); - - GridData data2 = new GridData(GridData.GRAB_HORIZONTAL - | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_FILL); - data2.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); - data2.heightHint = 200; - typeList.setLayoutData(data2); - typeList.setFont(parent.getFont()); - - typeList.showSelection(); - - applyDialogFont(composite); - return composite; - } - - private void loadComponents(Graph g) { - Resource projectResource = ProConfUI.getProject().getResource(); - Stack handling = new Stack(); - handling.push(projectResource); - - // this is just a hack to get equipment defined in ontologies - Resource projectsLib = g.getObjects(projectResource, g.getBuiltins().PartOf).iterator().next(); - Collection projects = g.getObjects(projectsLib, g.getBuiltins().ConsistsOf); - Resource typeSystemProject = null; - for (Resource project : projects) { - IEntity ent = EntityFactory.create(g,project); - String name = ent.getName(); - if(name.equals("Type System Project")) { - typeSystemProject = project; - break; - } - } - Collection ontologies = g.getObjects(typeSystemProject, g.getBuiltins().ConsistsOf); - for (Resource ontology : ontologies) { - if(g.isInstanceOf(ontology, g.getBuiltins().Ontology)) - handling.add(ontology); - } - - while (!handling.isEmpty()) { - final Resource node = handling.pop(); - if (g.isInstanceOf(node,primaryType)) { - IEntity equipment = EntityFactory.create(g, node); - Collection graphics = equipment - .getRelatedObjects(ProcessResource.plant3Dresource.HasGraphics); - if (graphics.size() != 1) { - ErrorLogger.defaultLogError("Equipment " - + equipment.getName() + " has " + graphics.size() - + " + graphical representation!", null); - } else { - boolean add = true; - for (Resource r : requiredTypes) { - if (!equipment.isInstanceOf(r)) { - add = false; - break; - } - } - if (add) { - for (Resource r : filteredTypes) { - if (equipment.isInstanceOf(r)) { - add = false; - break; - } - } - } - if (add) { - final String name = equipment.getName(); - getDialogArea().getDisplay().asyncExec(new Runnable() { - public void run() { - // List won't work with two ore more same names. - if (typeList.getData(name)!= null) { - String n = new String(name); - int i = 1; - while (true) { - n = name +"("+i+")"; - if (typeList.getData(n)== null) { - typeList.add(n); - typeList.setData(n, node); - break; - } - } - } else { - typeList.add(name); - typeList.setData(name, node); - } - } - }); - } - } - } else { - handling.addAll(g.getObjects(node, - ProcessResource.builtins.ConsistsOf)); - } - - } - - } - - -}