Java 类org.eclipse.gef.tools.CreationTool 实例源码

项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Try to find if the palette can create an element of a certain class. Because of current visibility restrictions, we can't actually look for factories or
 * try to create such an element. For now, we have to simply look for the template class used by the CombinedTemplateCreationEntry. Ideally, we should
 * search for the appropriate model creation factory.
 * 
 * @param c
 *            The template to find in one of UcmPaletteRoot's CombinedTemplateCreationEntry
 * @return the CreationTool that was found in the palette or null if none could be found
 */
private CreationTool getToolEntryForClass(Class c) {

    Stack s = new Stack();
    List l = getPaletteRoot().getChildren();
    for (int i = 0; i < l.size(); i++)
        s.push(l.get(i));

    while (s.size() > 0) {
        Object o = s.pop();
        if (o instanceof PaletteContainer) {
            l = ((PaletteContainer) o).getChildren();
            for (int i = 0; i < l.size(); i++)
                s.push(l.get(i));
        } else if (o instanceof CombinedTemplateCreationEntry) {
            Object template = ((CombinedTemplateCreationEntry) o).getTemplate();

            if (template == c) {
                return (CreationTool) ((CombinedTemplateCreationEntry) o).createTool();
            }
        }
    }
    return null;
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement: ReqComp
 * 
 * Author: jkealey
 */
public void testReqComp1() {

    // Is there a tool to create a ComponentRef in the palette?
    CreationTool createtool = getToolEntryForClass(ComponentRef.class);
    assertNotNull("No palette entry creates ComponentRef", createtool); //$NON-NLS-1$

    // verify that both the componentref and component element are not in the model
    assertEquals("Should be only one component in model", 1, urn.getUrndef().getComponents().size()); //$NON-NLS-1$
    assertEquals("Should be only one component reference in model", 1, getMap().getContRefs().size()); //$NON-NLS-1$

    // verify that the edit part tree is empty.
    assertEquals("MapAndPathGraphEditPart should have only two children", 2, getMapEditPart(0).getChildren().size()); //$NON-NLS-1$

    // simulate a CreateRequest that we would have liked to have obtained from the palette
    CreateRequest cr = getCreateRequest(new ModelCreationFactory(urn, ComponentRef.class, ComponentKind.TEAM), new Point(10, 100));
    assertNotNull("Unable to build create request", cr); //$NON-NLS-1$

    // create a command using this CreateRequest. Note that this is a compound command that not only creates the component but positions it properly.
    Command cmd = getMapEditPart(0).getCommand(cr);
    assertNotNull("Can't get command to obtain a new ComponentRef", cmd); //$NON-NLS-1$

    // execute the command, adding the componentref to the model
    getGraphicalViewer().getEditDomain().getCommandStack().execute(cmd);

    // because this test is not hooked up as a command stack change listener
    // JK: I'm not even sure how this should be done but we should do it.
    getMapEditPart(0).refreshChildren();

    // verify that both the componentref and component element have been added in the model.
    assertEquals("No component added to model", 2, urn.getUrndef().getComponents().size()); //$NON-NLS-1$
    assertEquals("No component ref added to model", 2, getMap().getContRefs().size()); //$NON-NLS-1$

    // verify that the edit part tree has changed.
    assertEquals("MapAndPathGraphEditPart should have exactly four children (2*component+label)", 4, getMapEditPart(0).getChildren().size()); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemDynamicStub
 * 
 * Author: jkealey
 */
public void testReqElemDynamicStub1() {
    // Is there a tool to create a Stub in the palette? without rewriting stuff, we can't get access to the creationfactory. assume dynamic exists if stub
    // exists
    CreationTool createtool = getToolEntryForClass(Stub.class);
    assertNotNull("No palette entry creates Stub", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemStaticStub
 * 
 * Author: jkealey
 */
public void testReqElemStaticStub1() {
    // Is there a tool to create a Stub in the palette? without rewriting stuff, we can't get access to the creationfactory. assume static exists if stub
    // exists
    CreationTool createtool = getToolEntryForClass(Stub.class);
    assertNotNull("No palette entry creates Stub", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:UrnDragSourceListener.java   
protected Object getTemplate() {
    List selection = getViewer().getSelectedEditParts();
    if (selection.size() == 1) {
        EditPart editpart = (EditPart) getViewer().getSelectedEditParts().get(0);
        Object model = editpart.getModel();
        if (model instanceof PaletteTemplateEntry)
            return ((PaletteTemplateEntry) model).getTemplate();
        if (model instanceof CombinedTemplateCreationEntry)
            return ((CombinedTemplateCreationEntry) model).getToolProperty(CreationTool.PROPERTY_CREATION_FACTORY);
    }
    return null;
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemAndFork
 * 
 * Author: jkealey
 */
public void testReqElemAndFork1() {
    // Is there a tool to create a AndFork in the palette?
    CreationTool createtool = getToolEntryForClass(AndFork.class);
    assertNotNull("No palette entry creates AndFork", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemAndJoin
 * 
 * Author: jkealey
 */
public void testReqElemAndJoin1() {
    // Is there a tool to create a AndJoin in the palette?
    CreationTool createtool = getToolEntryForClass(AndJoin.class);
    assertNotNull("No palette entry creates AndJoin", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemDirectionArrow
 * 
 * Author: jkealey
 */
public void testReqElemDirectionArrow1() {
    // Is there a tool to create a DirectionArrow in the palette?
    CreationTool createtool = getToolEntryForClass(DirectionArrow.class);
    assertNotNull("No palette entry creates DirectionArrow", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemOrFork
 * 
 * Author: jkealey
 */
public void testReqElemOrFork1() {
    // Is there a tool to create a OrFork in the palette?
    CreationTool createtool = getToolEntryForClass(OrFork.class);
    assertNotNull("No palette entry creates OrFork", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemOrJoin
 * 
 * Author: jkealey
 */
public void testReqElemOrJoin1() {
    // Is there a tool to create a OrJoin in the palette?
    CreationTool createtool = getToolEntryForClass(OrJoin.class);
    assertNotNull("No palette entry creates OrJoin", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemResponsibility
 * 
 * Author: jkealey
 */
public void testReqElemResponsibility1() {
    // Is there a tool to create a RespRef in the palette?
    CreationTool createtool = getToolEntryForClass(RespRef.class);
    assertNotNull("No palette entry creates RespRef", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemTimer
 * 
 * Author: jkealey
 */
public void testReqElemTimer1() {
    // Is there a tool to create a Timer in the palette?
    CreationTool createtool = getToolEntryForClass(Timer.class);
    assertNotNull("No palette entry creates Timer", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:ProgressTests.java   
/**
 * Test #1 for requirement ReqElemWait
 * 
 * Author: jkealey
 */
public void testReqElemWait1() {
    // Is there a tool to create a WaitingPlace in the palette?
    CreationTool createtool = getToolEntryForClass(WaitingPlace.class);
    assertNotNull("No palette entry creates WaitingPlace", createtool); //$NON-NLS-1$
}
项目:seg.jUCMNav    文件:BaseConnectionCreationToolEntry.java   
public Tool createTool() {
    return new BaseConnectionCreationTool((CreationFactory)getToolProperty(CreationTool.PROPERTY_CREATION_FACTORY));
}
项目:gef-gwt    文件:CreationToolEntry.java   
/**
 * Constructor for CreationToolEntry.
 * 
 * @param label
 *            the label
 * @param shortDesc
 *            the description
 * @param factory
 *            the CreationFactory
 * @param iconSmall
 *            the small icon
 * @param iconLarge
 *            the large icon
 */
public CreationToolEntry(String label, String shortDesc,
        CreationFactory factory, ImageDescriptor iconSmall,
        ImageDescriptor iconLarge) {
    super(label, shortDesc, iconSmall, iconLarge, CreationTool.class);
    this.factory = factory;
    setToolProperty(CreationTool.PROPERTY_CREATION_FACTORY, factory);
}