X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FNewMasterTypicalDiagram.java;fp=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Ftypicals%2FNewMasterTypicalDiagram.java;h=e6dc21c7e54a821e602d565ae1725da1914701f8;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewMasterTypicalDiagram.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewMasterTypicalDiagram.java new file mode 100644 index 000000000..e6dc21c7e --- /dev/null +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/typicals/NewMasterTypicalDiagram.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2012 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.ui.typicals; + +import java.lang.reflect.InvocationTargetException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.simantics.Simantics; +import org.simantics.browsing.ui.common.ErrorLogger; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.modeling.ModelingResources; +import org.simantics.modeling.typicals.TypicalUtil; +import org.simantics.ui.workbench.action.ChooseActionRequest; +import org.simantics.utils.ui.SWTUtils; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * Creates a new master typical diagram and its corresponding composites. + * + *

+ * The created typical composite and diagram type are specified by the model + * using {@link ModelingResources#StructuralModel_HasTypicalCompositeBaseType} + * and {@link ModelingResources#StructuralModel_HasTypicalDiagramBaseType}. + * + *

+ * Marks the created master composite with the model-specified master composite + * type to support searching. The master type is specified by the model using + * {@link ModelingResources#StructuralModel_HasMasterTypicalCompositeType}. + * + *

+ * Clones symbol contributions from the sources specified by the model through + * {@link ModelingResources#StructuralModel_CloneTypicalDiagramSymbolContributionsFrom} + * . + * + * @author Tuukka Lehtonen + */ +public class NewMasterTypicalDiagram implements ActionFactory { + + @Override + public Runnable create(Object target_) { + final Resource target = (Resource)target_; + return new Runnable() { + @Override + public void run() { + try { + PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + Resource composite = TypicalUtil.newMasterTypical(target); + + // Perform default action on the newly created diagram + performDefaultAction(Simantics.getSession(), composite); + } catch (DatabaseException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }); + } catch (InvocationTargetException e) { + ErrorLogger.defaultLogError(e); + } catch (InterruptedException e) { + ErrorLogger.defaultLogError(e); + } + } + }; + }; + + private static void performDefaultAction(final Session session, final Object input) { + SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), new Runnable() { + @Override + public void run() { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + Shell shell = window != null ? window.getShell() : null; + session.asyncRequest(new ChooseActionRequest(shell, null, input, WorkbenchUtils.getCurrentPerspectiveId(), false, false, true)); + } + }); + } + +}