/******************************************************************************* | |
* <copyright> | |
* | |
* Copyright (c) 2013, 2013 SAP AG. | |
* 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: | |
* SAP AG - initial API, implementation and documentation | |
* | |
* </copyright> | |
* | |
*******************************************************************************/ | |
package org.eclipse.fmc.blockdiagram.editor; | |
import org.eclipse.core.runtime.CoreException; | |
import org.eclipse.core.runtime.IConfigurationElement; | |
import org.eclipse.core.runtime.IExtensionRegistry; | |
import org.eclipse.core.runtime.Platform; | |
import org.eclipse.gef.palette.PaletteContainer; | |
import org.eclipse.gef.palette.PaletteDrawer; | |
import org.eclipse.gef.palette.PaletteEntry; | |
import org.eclipse.gef.palette.PaletteRoot; | |
import org.eclipse.graphiti.ui.editor.DefaultPaletteBehavior; | |
import org.eclipse.graphiti.ui.editor.DiagramBehavior; | |
/** | |
* This custom palette behavior allows the addition of new palette tool entries | |
* via the dedicated extension point. | |
* | |
* | |
* @author Benjamin Schmeling | |
*/ | |
public class BlockDiagramPaletteBehavior extends DefaultPaletteBehavior { | |
public BlockDiagramPaletteBehavior(DiagramBehavior diagramBehavior) { | |
super(diagramBehavior); | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.ui.editor.DefaultPaletteBehavior#createPaletteRoot() | |
*/ | |
protected PaletteRoot createPaletteRoot() { | |
PaletteRoot root = super.createPaletteRoot(); | |
// Creates new palette container for extensions | |
PaletteContainer container = new PaletteDrawer("Extensions"); | |
try { | |
addFromExtensionPoint(container); | |
} catch (CoreException e) { | |
e.printStackTrace(); | |
} | |
if (!container.getChildren().isEmpty()) | |
root.add(container); | |
return root; | |
} | |
/** | |
* Adds new entries if registered via org.eclipse.fmc.blockdiagram.editor.palette | |
* extension. | |
* | |
* @param container | |
* The palette container. | |
* @throws CoreException | |
*/ | |
private void addFromExtensionPoint(PaletteContainer container) | |
throws CoreException { | |
IExtensionRegistry reg = Platform.getExtensionRegistry(); | |
IConfigurationElement[] extensions = reg | |
.getConfigurationElementsFor("org.eclipse.fmc.blockdiagram.editor.palette"); | |
for (IConfigurationElement element : extensions) { | |
PaletteEntry entry = (PaletteEntry) element | |
.createExecutableExtension("class"); | |
entry.setLabel(element.getAttribute("label")); | |
entry.setDescription(element.getAttribute("shortDescription")); | |
container.add(entry); | |
} | |
} | |
} |