X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2FDoubleClickExtension.java;fp=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2FDoubleClickExtension.java;h=3407f21c0c6835d64b47d04b0dd7ea41ecfb07d4;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/DoubleClickExtension.java b/bundles/org.simantics.ui/src/org/simantics/ui/DoubleClickExtension.java new file mode 100644 index 000000000..3407f21c0 --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/DoubleClickExtension.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.simantics.db.exception.DatabaseException; +import org.simantics.utils.ui.ExceptionUtils; + +public class DoubleClickExtension implements IDoubleClickExtension { + + /** + * A fallback action for replacing {@link #cachedAction} if action + * instantiation fails. + */ + private static final IDoubleClickAction NO_ACTION = new IDoubleClickAction() { + @Override + public void doubleClickEvent(DoubleClickEvent e) throws DatabaseException { + } + }; + + private final IConfigurationElement config; + + private final String name; + + private final double priority; + + private IDoubleClickAction cachedAction; + + DoubleClickExtension(IConfigurationElement config, String name, double priority) { + this.config = config; + this.name = name; + this.priority = priority; + } + + @Override + public String getName() { + return name; + } + + @Override + public double getPriority() { + return priority; + } + + @Override + public synchronized IDoubleClickAction getAction() { + if (cachedAction == null) { + try { + cachedAction = (IDoubleClickAction) config.createExecutableExtension("class"); + } catch (CoreException e) { + ExceptionUtils.logError("Failed to instantiate " + config.getName() + + " extension with name \"" + config.getAttribute("name") + "\": " + + e.getMessage(), e); + // This prevents informing of an error in the extension. + cachedAction = NO_ACTION; + } + } + return cachedAction; + } + + @Override + public String toString() { + return "DoubleClickExtension [name=" + name + ", class=" + config.getAttribute("class") + ", priority=" + priority + "]"; + } + +}