X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fhandlers%2FNewEquipmentHandler.java;fp=org.simantics.processeditor%2Fsrc%2Forg%2Fsimantics%2Fprocesseditor%2Fhandlers%2FNewEquipmentHandler.java;h=0000000000000000000000000000000000000000;hb=6b6fcff5d6c326feef07ccf8401f97911778fffe;hp=a204f5167695bbf48ceceb057c0d8941a23ab49a;hpb=504c111db40d78f4913badddd126b283b5504dbb;p=simantics%2F3d.git diff --git a/org.simantics.processeditor/src/org/simantics/processeditor/handlers/NewEquipmentHandler.java b/org.simantics.processeditor/src/org/simantics/processeditor/handlers/NewEquipmentHandler.java deleted file mode 100644 index a204f516..00000000 --- a/org.simantics.processeditor/src/org/simantics/processeditor/handlers/NewEquipmentHandler.java +++ /dev/null @@ -1,120 +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.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.db.Graph; -import org.simantics.db.GraphRequestAdapter; -import org.simantics.db.GraphRequestStatus; -import org.simantics.db.Resource; -import org.simantics.layer0.stubs.Library; -import org.simantics.layer0.utils.EntityFactory; -import org.simantics.layer0.utils.IEntity; -import org.simantics.layer0.utils.instantiation.InstanceFactory; -import org.simantics.processeditor.ProcessResource; -import org.simantics.processeditor.stubs.Equipment; -import org.simantics.proconf.ui.ProConfUI; -import org.simantics.proconf.ui.utils.ResourceAdaptionUtils; - - -/** - * Creates new equipment - * - * @author Marko Luukkainen - * - */ -public class NewEquipmentHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection s = HandlerUtil.getCurrentSelectionChecked(event); - IStructuredSelection ss = (IStructuredSelection) s; - if (ss.size() != 1) - return null; - final Resource lib = ResourceAdaptionUtils.toSingleResource(ss); - - EquipmentDialog dialog = new EquipmentDialog(Display.getDefault().getActiveShell()); - if (dialog.open() == EquipmentDialog.CANCEL) - return null; - final String name = dialog.getName(); - if (name == null || name.length() == 0) - return null; - ProConfUI.getSession().asyncWrite(new GraphRequestAdapter() { - @Override - public GraphRequestStatus perform(Graph g) throws Exception { - Equipment equipment = Equipment.createDefault(g); - Library l = new Library(g, lib); - l.addStatement(g.getBuiltins().ConsistsOf, equipment); - - // TODO : is this correct (instance & inherits) - equipment.addStatement(ProcessResource.builtins.Inherits, ProcessResource.plant3Dresource.Equipment); - - Resource modelType = g.getResourceByURI("http://www.vtt.fi/Simantics/CSG/1.0/Types#CSGModel"); - IEntity model = EntityFactory.create(g, InstanceFactory.instantiate(g, modelType)); - equipment.addStatement(ProcessResource.plant3Dresource.HasGraphics, model); - equipment.setName(name); - return GraphRequestStatus.transactionComplete(); - } - }); - - - return null; - } - - private class EquipmentDialog extends Dialog { - - private String name; - - public EquipmentDialog(Shell shell) { - super(shell); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite composite = (Composite) super.createDialogArea(parent); - Label label = new Label(composite,SWT.NONE); - label.setText("Name:"); - Text text = new Text(composite,SWT.SINGLE|SWT.BORDER); - text.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - name = ((Text)e.widget).getText(); - } - }); - GridData data = new GridData(); - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = SWT.FILL; - text.setLayoutData(data); - return composite; - } - - public String getName() { - return name; - } - } - -}