001: package org.drools.eclipse.flow.ruleflow.editor;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.drools.eclipse.DroolsEclipsePlugin;
023: import org.drools.eclipse.flow.common.editor.core.ElementConnectionFactory;
024: import org.drools.eclipse.flow.ruleflow.core.ActionWrapper;
025: import org.drools.eclipse.flow.ruleflow.core.ConnectionWrapper;
026: import org.drools.eclipse.flow.ruleflow.core.ConnectionWrapperFactory;
027: import org.drools.eclipse.flow.ruleflow.core.EndNodeWrapper;
028: import org.drools.eclipse.flow.ruleflow.core.JoinWrapper;
029: import org.drools.eclipse.flow.ruleflow.core.MilestoneWrapper;
030: import org.drools.eclipse.flow.ruleflow.core.RuleSetNodeWrapper;
031: import org.drools.eclipse.flow.ruleflow.core.SplitWrapper;
032: import org.drools.eclipse.flow.ruleflow.core.StartNodeWrapper;
033: import org.drools.eclipse.flow.ruleflow.core.SubFlowWrapper;
034: import org.drools.ruleflow.core.Connection;
035: import org.eclipse.gef.palette.CombinedTemplateCreationEntry;
036: import org.eclipse.gef.palette.ConnectionCreationToolEntry;
037: import org.eclipse.gef.palette.MarqueeToolEntry;
038: import org.eclipse.gef.palette.PaletteContainer;
039: import org.eclipse.gef.palette.PaletteDrawer;
040: import org.eclipse.gef.palette.PaletteGroup;
041: import org.eclipse.gef.palette.PaletteRoot;
042: import org.eclipse.gef.palette.SelectionToolEntry;
043: import org.eclipse.gef.palette.ToolEntry;
044: import org.eclipse.gef.requests.CreationFactory;
045: import org.eclipse.gef.requests.SimpleFactory;
046: import org.eclipse.jface.resource.ImageDescriptor;
047:
048: /**
049: * Factory for creating a RuleFlow palette.
050: *
051: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
052: */
053: public class RuleFlowPaletteFactory {
054:
055: public static PaletteRoot createPalette() {
056: PaletteRoot flowPalette = new PaletteRoot();
057: flowPalette.addAll(createCategories(flowPalette));
058: return flowPalette;
059: }
060:
061: private static List createCategories(PaletteRoot root) {
062: List categories = new ArrayList();
063: categories.add(createControlGroup(root));
064: categories.add(createComponentsDrawer());
065: return categories;
066: }
067:
068: private static PaletteContainer createComponentsDrawer() {
069:
070: PaletteDrawer drawer = new PaletteDrawer("Components", null);
071:
072: List entries = new ArrayList();
073:
074: CombinedTemplateCreationEntry combined = new CombinedTemplateCreationEntry(
075: "Start", "Create a new Start", StartNodeWrapper.class,
076: new SimpleFactory(StartNodeWrapper.class),
077: ImageDescriptor.createFromURL(DroolsEclipsePlugin
078: .getDefault().getBundle().getEntry(
079: "icons/process_start.gif")),
080: ImageDescriptor.createFromURL(DroolsEclipsePlugin
081: .getDefault().getBundle().getEntry(
082: "icons/process_start.gif")));
083: entries.add(combined);
084:
085: combined = new CombinedTemplateCreationEntry("End",
086: "Create a new End", EndNodeWrapper.class,
087: new SimpleFactory(EndNodeWrapper.class),
088: ImageDescriptor.createFromURL(DroolsEclipsePlugin
089: .getDefault().getBundle().getEntry(
090: "icons/process_stop.gif")),
091: ImageDescriptor.createFromURL(DroolsEclipsePlugin
092: .getDefault().getBundle().getEntry(
093: "icons/process_stop.gif")));
094: entries.add(combined);
095:
096: combined = new CombinedTemplateCreationEntry("RuleFlowGroup",
097: "Create a new RuleFlowGroup", RuleSetNodeWrapper.class,
098: new SimpleFactory(RuleSetNodeWrapper.class),
099: ImageDescriptor.createFromURL(DroolsEclipsePlugin
100: .getDefault().getBundle().getEntry(
101: "icons/activity.gif")), ImageDescriptor
102: .createFromURL(DroolsEclipsePlugin.getDefault()
103: .getBundle().getEntry(
104: "icons/activity.gif")));
105: entries.add(combined);
106:
107: combined = new CombinedTemplateCreationEntry("Split",
108: "Create a new Split", SplitWrapper.class,
109: new SimpleFactory(SplitWrapper.class), ImageDescriptor
110: .createFromURL(DroolsEclipsePlugin.getDefault()
111: .getBundle()
112: .getEntry("icons/split.gif")),
113: ImageDescriptor.createFromURL(DroolsEclipsePlugin
114: .getDefault().getBundle().getEntry(
115: "icons/split.gif")));
116: entries.add(combined);
117:
118: combined = new CombinedTemplateCreationEntry("Join",
119: "Create a new Join", JoinWrapper.class,
120: new SimpleFactory(JoinWrapper.class),
121: ImageDescriptor.createFromURL(DroolsEclipsePlugin
122: .getDefault().getBundle().getEntry(
123: "icons/join.gif")),
124: ImageDescriptor.createFromURL(DroolsEclipsePlugin
125: .getDefault().getBundle().getEntry(
126: "icons/join.gif")));
127: entries.add(combined);
128:
129: combined = new CombinedTemplateCreationEntry("Milestone",
130: "Create a new Milestone", MilestoneWrapper.class,
131: new SimpleFactory(MilestoneWrapper.class),
132: ImageDescriptor.createFromURL(DroolsEclipsePlugin
133: .getDefault().getBundle().getEntry(
134: "icons/question.gif")), ImageDescriptor
135: .createFromURL(DroolsEclipsePlugin.getDefault()
136: .getBundle().getEntry(
137: "icons/question.gif")));
138: entries.add(combined);
139:
140: combined = new CombinedTemplateCreationEntry("SubFlow",
141: "Create a new SubFlow", SubFlowWrapper.class,
142: new SimpleFactory(SubFlowWrapper.class),
143: ImageDescriptor.createFromURL(DroolsEclipsePlugin
144: .getDefault().getBundle().getEntry(
145: "icons/process.gif")), ImageDescriptor
146: .createFromURL(DroolsEclipsePlugin.getDefault()
147: .getBundle().getEntry(
148: "icons/process.gif")));
149: entries.add(combined);
150:
151: combined = new CombinedTemplateCreationEntry("Action",
152: "Create a new Action", ActionWrapper.class,
153: new SimpleFactory(ActionWrapper.class), ImageDescriptor
154: .createFromURL(DroolsEclipsePlugin.getDefault()
155: .getBundle().getEntry(
156: "icons/action.gif")),
157: ImageDescriptor.createFromURL(DroolsEclipsePlugin
158: .getDefault().getBundle().getEntry(
159: "icons/action.gif")));
160: entries.add(combined);
161:
162: drawer.addAll(entries);
163: return drawer;
164: }
165:
166: private static PaletteContainer createControlGroup(PaletteRoot root) {
167: PaletteGroup controlGroup = new PaletteGroup("Control Group");
168:
169: List entries = new ArrayList();
170:
171: ToolEntry tool = new SelectionToolEntry();
172: entries.add(tool);
173: root.setDefaultEntry(tool);
174:
175: tool = new MarqueeToolEntry();
176: entries.add(tool);
177:
178: final ElementConnectionFactory normalConnectionFactory = new ConnectionWrapperFactory(
179: Connection.TYPE_NORMAL);
180:
181: tool = new ConnectionCreationToolEntry("Connection Creation",
182: "Creating connections", new CreationFactory() {
183: public Object getNewObject() {
184: return normalConnectionFactory
185: .createElementConnection();
186: }
187:
188: public Object getObjectType() {
189: return ConnectionWrapper.class;
190: }
191: }, ImageDescriptor.createFromURL(DroolsEclipsePlugin
192: .getDefault().getBundle().getEntry(
193: "icons/connection.gif")),
194: ImageDescriptor.createFromURL(DroolsEclipsePlugin
195: .getDefault().getBundle().getEntry(
196: "icons/connection.gif")));
197: entries.add(tool);
198:
199: controlGroup.addAll(entries);
200: return controlGroup;
201: }
202: }
|