X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Fcontribution%2FDynamicMenuContribution.java;h=95bc5b423f756b0eb15809d0845a33009f1c8f91;hb=fbfec9e8c7d8d768d9c6327060d9333b2feaea81;hp=728375b143babe4f7f395b2b75d45238a7045de5;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/DynamicMenuContribution.java b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/DynamicMenuContribution.java index 728375b14..95bc5b423 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/contribution/DynamicMenuContribution.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/contribution/DynamicMenuContribution.java @@ -1,182 +1,182 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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.ui.contribution; - -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.ISelectionService; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.CompoundContributionItem; -import org.simantics.DatabaseJob; -import org.simantics.Simantics; -import org.simantics.db.ReadGraph; -import org.simantics.db.common.request.UniqueRead; -import org.simantics.db.common.utils.RequestUtil; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.ErrorLogger; - -/** - * A more or less carbon copy of CompoundContributionItem with the exception of - * adding Simantics Graph database traits to the menu filling process. - * - *
- * The simplest way to use this class is to override the - * {@link #getActions(ReadGraph, Object[])} method which should return any - * actions that you want to be performed on the specified selection. Another way - * is to override {@link #getContributionItems(ReadGraph, Object[])} that by - * default simply invokes the simplest method - * {@link #getActions(ReadGraph, Object[])}. Overriding it allows you to create - * e.g. submenus, which you cannot do with actions. - *
- * - *- * To customize what gets passed to either - * {@link #getActions(ReadGraph, Object[])} or - * {@link #getContributionItems(ReadGraph, Object[])} as the selection - * parameter, override {@link #getSelectedObjects()} - *
- * - * @author Tuukka Lehtonen - */ -public abstract class DynamicMenuContribution extends CompoundContributionItem { - - protected static final Object[] NO_OBJECTS = {}; - protected static final IAction[] NO_ACTIONS = {}; - protected static final IContributionItem[] NONE = {}; - - /** - * Creates a contribution item with anull
id.
- */
- protected DynamicMenuContribution() {
- super();
- }
-
- /**
- * Creates a contribution item with the given (optional) id.
- *
- * @param id the contribution item identifier, or null
- */
- protected DynamicMenuContribution(String id) {
- super(id);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
- */
- @Override
- protected final IContributionItem[] getContributionItems() {
- if (DatabaseJob.inProgress())
- return NONE;
- ISessionContext ctx = SimanticsUI.getSessionContext();
- if (ctx != null) {
- final Object[] selection = getSelectedObjects();
- //System.out.println(getClass().getSimpleName() + "@" + System.identityHashCode(this) + "( " + System.identityHashCode(selection) + ": " + Arrays.toString(selection) + " )");
- if (!preAcceptSelection(selection))
- return NONE;
- try {
- return RequestUtil.trySyncRequest(
- Simantics.getSession(),
- SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
- SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT_LONG,
- NONE,
- new UniqueRead- * The default implementation checks that the input selection is not empty. - * To be able to provide contributions for empty selection, you must - * override this method. - * - * @param selection - * @return - */ - protected boolean preAcceptSelection(Object[] selection) { - return selection != null && selection.length > 0; - } - - protected IContributionItem[] getContributionItems(ReadGraph graph, Object[] selection) throws DatabaseException { - return toContributionItems( getActions(graph, selection) ); - } - - protected IAction[] getActions(ReadGraph graph, Object[] selection) throws DatabaseException { - return new IAction[0]; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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.ui.contribution; + +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.CompoundContributionItem; +import org.simantics.DatabaseJob; +import org.simantics.Simantics; +import org.simantics.db.ReadGraph; +import org.simantics.db.common.request.UniqueRead; +import org.simantics.db.common.utils.RequestUtil; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.management.ISessionContext; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ErrorLogger; + +/** + * A more or less carbon copy of CompoundContributionItem with the exception of + * adding Simantics Graph database traits to the menu filling process. + * + *
+ * The simplest way to use this class is to override the + * {@link #getActions(ReadGraph, Object[])} method which should return any + * actions that you want to be performed on the specified selection. Another way + * is to override {@link #getContributionItems(ReadGraph, Object[])} that by + * default simply invokes the simplest method + * {@link #getActions(ReadGraph, Object[])}. Overriding it allows you to create + * e.g. submenus, which you cannot do with actions. + *
+ * + *+ * To customize what gets passed to either + * {@link #getActions(ReadGraph, Object[])} or + * {@link #getContributionItems(ReadGraph, Object[])} as the selection + * parameter, override {@link #getSelectedObjects()} + *
+ * + * @author Tuukka Lehtonen + */ +public abstract class DynamicMenuContribution extends CompoundContributionItem { + + protected static final Object[] NO_OBJECTS = {}; + protected static final IAction[] NO_ACTIONS = {}; + protected static final IContributionItem[] NONE = {}; + + /** + * Creates a contribution item with anull
id.
+ */
+ protected DynamicMenuContribution() {
+ super();
+ }
+
+ /**
+ * Creates a contribution item with the given (optional) id.
+ *
+ * @param id the contribution item identifier, or null
+ */
+ protected DynamicMenuContribution(String id) {
+ super(id);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ @Override
+ protected final IContributionItem[] getContributionItems() {
+ if (DatabaseJob.inProgress())
+ return NONE;
+ ISessionContext ctx = Simantics.getSessionContext();
+ if (ctx != null) {
+ final Object[] selection = getSelectedObjects();
+ //System.out.println(getClass().getSimpleName() + "@" + System.identityHashCode(this) + "( " + System.identityHashCode(selection) + ": " + Arrays.toString(selection) + " )");
+ if (!preAcceptSelection(selection))
+ return NONE;
+ try {
+ return RequestUtil.trySyncRequest(
+ Simantics.getSession(),
+ SimanticsUI.UI_THREAD_REQUEST_START_TIMEOUT,
+ SimanticsUI.UI_THREAD_REQUEST_EXECUTION_TIMEOUT_LONG,
+ NONE,
+ new UniqueRead+ * The default implementation checks that the input selection is not empty. + * To be able to provide contributions for empty selection, you must + * override this method. + * + * @param selection + * @return + */ + protected boolean preAcceptSelection(Object[] selection) { + return selection != null && selection.length > 0; + } + + protected IContributionItem[] getContributionItems(ReadGraph graph, Object[] selection) throws DatabaseException { + return toContributionItems( getActions(graph, selection) ); + } + + protected IAction[] getActions(ReadGraph graph, Object[] selection) throws DatabaseException { + return new IAction[0]; + } + +}