Example usage for org.eclipse.jface.viewers LabelProvider LabelProvider

List of usage examples for org.eclipse.jface.viewers LabelProvider LabelProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers LabelProvider LabelProvider.

Prototype

public LabelProvider() 

Source Link

Document

Creates a new label provider.

Usage

From source file:de.tub.tfs.henshin.editor.util.DialogUtil.java

License:Open Source License

/**
 * Run node creation dialog./*from www.ja v a  2s .com*/
 * 
 * @param shell
 *            the shell
 * @param graph
 *            the graph
 * @return the e class
 */
public static EClass runNodeCreationDialog(Shell shell, Graph graph) {
    List<EClass> nodeTypes = new ArrayList<EClass>();
    Module transSys = HenshinUtil.INSTANCE.getTransformationSystem(graph);

    if (canCreateNode(shell, graph)) {
        if (transSys != null) {
            EList<EPackage> imports = transSys.getImports();

            for (EPackage ePackage : imports) {
                nodeTypes.addAll(NodeTypes.getNodeTypesOfEPackage(ePackage, false));
            }
        }

        // =============================================================
        // TODO: ?? why ??: This causes creation dialog not to be shown up, if graph is empty.
        // nodeTypes = NodeTypes.getNodeTypes(graph, graph.eContainer() != transSys);
        // ===========================================================

        switch (nodeTypes.size()) {
        case 0:
            break;
        case 1:
            return nodeTypes.get(0);
        default:
            return new ExtendedElementListSelectionDialog<EClass>(shell, new LabelProvider() {
                @Override
                public String getText(Object element) {
                    return ((EClass) element).getName();
                }

                @Override
                public Image getImage(Object element) {
                    return IconUtil.getIcon("node18.png");
                }
            }, nodeTypes.toArray(new EClass[nodeTypes.size()]), "Node Type Selection",
                    "Select a EClass for the new node type:").runSingle();
        }
    }

    return null;
}

From source file:de.tub.tfs.henshin.editor.util.DialogUtil.java

License:Open Source License

/**
 * Run edge type selection dialog./*from  w  ww  .  jav  a 2s.c  o  m*/
 * 
 * @param shell
 *            the shell
 * @param eReferences
 *            the e references
 * @return the e reference
 */
public static EReference runEdgeTypeSelectionDialog(Shell shell, List<EReference> eReferences) {
    switch (eReferences.size()) {
    case 0:
        return null;
    case 1:
        return eReferences.get(0);
    default:
        return new ExtendedElementListSelectionDialog<EReference>(shell, new LabelProvider() {
            @Override
            public String getText(Object element) {
                return ((EReference) element).getName();
            }

            @Override
            public Image getImage(Object element) {
                return IconUtil.getIcon("edge18.png");
            }
        }, eReferences.toArray(new EReference[eReferences.size()]), "Edge Type Selection",
                "Select a EReference for the new edge type:").runSingle();
    }
}

From source file:de.tub.tfs.henshin.editor.util.DialogUtil.java

License:Open Source License

/**
 * Run graph choice dialog./*from  www  . j av  a  2s  . co  m*/
 * 
 * @param shell
 *            the shell
 * @param graphs
 *            the graphen
 * @return the graph
 */
public static Graph runGraphChoiceDialog(Shell shell, List<Graph> graphs) {
    return new ExtendedElementListSelectionDialog<Graph>(shell, new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Graph) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return IconUtil.getIcon("graph18.png");
        }
    }, graphs.toArray(new Graph[graphs.size()]), "Graph Selection", "Select a Graph for transformation:")
            .runSingle();
}

From source file:de.tub.tfs.henshin.editor.util.DialogUtil.java

License:Open Source License

/**
 * Run rule choice dialog./*from  www.jav  a  2 s.c  o  m*/
 * 
 * @param shell
 *            the shell
 * @param rules
 *            the rules
 * @return the rule
 */
public static Rule runRuleChoiceDialog(Shell shell, List<Rule> rules) {
    return new ExtendedElementListSelectionDialog<Rule>(shell, new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Rule) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            return ResourceUtil.ICONS.RULE.img(16);
        }
    }, rules.toArray(new Rule[rules.size()]), Messages.RULE_SELECTION, Messages.RULE_SELECTION_MSG).runSingle();
}

From source file:de.tub.tfs.henshin.editor.util.DialogUtil.java

License:Open Source License

/**
 * Run transformation unit choice dialog.
 * /* ww w .j a  va2 s  .  co  m*/
 * @param shell
 *            the shell
 * @param transUnits
 *            the trans units
 * @return the transformation unit
 */
public static Unit runTransformationUnitChoiceDialog(Shell shell, List<Unit> transUnits) {
    return new ExtendedElementListSelectionDialog<Unit>(shell, new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Unit) element).getName();
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof Rule) {
                return IconUtil.getIcon("ruler16.png");
            }

            if (element instanceof ConditionalUnit) {
                return IconUtil.getIcon("conditionalUnit18.png");
            }
            if (element instanceof SequentialUnit) {
                return IconUtil.getIcon("seqUnit18.png");
            }
            if (element instanceof IndependentUnit) {
                return IconUtil.getIcon("independent16.png");
            }
            if (element instanceof PriorityUnit) {
                return IconUtil.getIcon("priority16.png");
            }

            return null;
        }
    }, transUnits.toArray(new Unit[transUnits.size()]), "Transformation Unit Selection",
            "Select a Transformation Unit:").runSingle();
}

From source file:de.tub.tfs.henshin.tggeditor.actions.create.rule.CreatePrototypeRulesAction.java

License:Open Source License

@Override
public void run() {
    Shell shell = new Shell();

    List<EClass> nodeTypes = new LinkedList<EClass>();

    TGG system = GraphicalNodeUtil.getLayoutSystem(transSys);

    List<EPackage> epackages = getPackages(system, TripleComponent.SOURCE);

    nodeTypes = NodeTypes.getNodeTypesOfEPackages(epackages, false);

    EClass eClass = new SingleElementListSelectionDialog<EClass>(shell, new LabelProvider() {
        @Override//  ww w .  ja  v  a 2 s  .com
        public String getText(Object element) {
            return ((EClass) element).getName();
        }

        //               @Override
        //               public Image getImage(Object element) {
        //                  return IconUtil.getIcon("node18.png");
        //               }
    }, nodeTypes.toArray(new EClass[nodeTypes.size()]), "Node Type Selection",
            "Select a EClass for the prototype rules:").run();

    shell.close();

    List<Rule> rules = buildPrototype(eClass);

    transSys.getUnits().addAll(rules);

    super.run();
}

From source file:de.tub.tfs.henshin.tggeditor.actions.create.rule.CreateRecPrototypeRulesAction.java

License:Open Source License

@Override
public void run() {
    Shell shell = new Shell();

    List<EClass> nodeTypes = new LinkedList<EClass>();

    TGG system = GraphicalNodeUtil.getLayoutSystem(transSys);

    List<EPackage> epackages = getPackages(system, TripleComponent.SOURCE);

    nodeTypes = NodeTypes.getNodeTypesOfEPackages(epackages, false);

    EClass eClass = new SingleElementListSelectionDialog<EClass>(shell, new LabelProvider() {
        @Override/*from  w  w w .  j  a v  a  2  s. c o m*/
        public String getText(Object element) {
            return ((EClass) element).getName();
        }

        //               @Override
        //               public Image getImage(Object element) {
        //                  return IconUtil.getIcon("node18.png");
        //               }
    }, nodeTypes.toArray(new EClass[nodeTypes.size()]), "Node Type Selection",
            "Select a EClass for the prototype rules:").run();

    shell.close();

    //convertedClasses.clear();
    List<Rule> rules = buildPrototype(eClass);
    Collections.sort(rules, new Comparator<Rule>() {

        @Override
        public int compare(Rule o1, Rule o2) {
            // TODO Auto-generated method stub
            return o1.getName().compareTo(o2.getName());
        }
    });
    transSys.getUnits().addAll(rules);

    super.run();
}

From source file:de.tub.tfs.henshin.tggeditor.util.dialogs.DialogUtil.java

License:Open Source License

/**
 * Run node creation dialog./*from  w  ww  . j ava2s  .c  o  m*/
 * 
 * @param shell
 *            the shell
 * @param tripleGraph
 *            the graph
 * @return the e class
 */
public static EClass runNodeCreationDialog(Shell shell, CreateNodeCommand c) {
    TGG layoutModel = c.getLayoutModel();
    Graph graph = c.getGraph();

    List<EClass> nodeTypes = new ArrayList<EClass>();
    Module transSys = (Module) graph.eResource().getContents().get(0);

    if (canCreateNode(shell, graph, layoutModel, c.getNodeTripleComponent())) {

        List<EPackage> epackages = getPackages(layoutModel, c.getNodeTripleComponent());

        nodeTypes = NodeTypes.getNodeTypesOfEPackages(epackages, graph.eContainer() != transSys);
        EPackage ecorePackage = EcorePackage.eINSTANCE;
        List<EClass> nodeTypes2 = new ArrayList<EClass>();
        nodeTypes2 = NodeTypes.getNodeTypesOfEPackage(ecorePackage, graph.eContainer() != transSys);
        nodeTypes.addAll(nodeTypes2);
        switch (nodeTypes.size()) {
        case 0:
            return null;
        case 1:
            return nodeTypes.get(0);
        default:
            return new SingleElementListSelectionDialog<EClass>(shell, new LabelProvider() {
                @Override
                public String getText(Object element) {
                    return ((EClass) element).getName();
                }

                //                     @Override
                //                     public Image getImage(Object element) {
                //                        return IconUtil.getIcon("node18.png");
                //                     }
            }, nodeTypes.toArray(new EClass[nodeTypes.size()]), "Node Type Selection",
                    "Select a EClass for the new node type:").run();
        }
    }
    return null;
}

From source file:de.tub.tfs.henshin.tggeditor.util.dialogs.DialogUtil.java

License:Open Source License

/**
 * Run node creation dialog./*from  w  w  w  . j  av  a 2s  .  c om*/
 * 
 * @param shell
 *            the shell
 * @param tripleGraph
 *            the graph
 * @return the e class
 */
public static EClass runClassSelectionDialog(Shell shell, List<EClassifier> c, EClassifier source,
        ListEntry<EClass>... entries) {

    List<EClass> nodeTypes = new ArrayList<EClass>();

    for (EClassifier eClassifier : c) {
        if (eClassifier instanceof EClass) {
            nodeTypes.add((EClass) eClassifier);
        }
    }

    return new SingleElementListSelectionDialog<EClass>(shell, new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((EClass) element).getName();
        }

        //                     @Override
        //                     public Image getImage(Object element) {
        //                        return IconUtil.getIcon("node18.png");
        //                     }
    }, nodeTypes.toArray(new EClass[nodeTypes.size()]), source.getName(),
            ("Select a EClass for the mapping to " + source.getName() + ":"), entries).run();

}

From source file:de.tub.tfs.henshin.tggeditor.util.dialogs.DialogUtil.java

License:Open Source License

/**
 * Run edge type selection dialog.//from w  ww.  j a  v a2 s . c  o m
 * 
 * @param shell
 *            the shell
 * @param eReferences
 *            the e references
 * @return the e reference
 */
public static EReference runEdgeTypeSelectionDialog(Shell shell, List<EReference> eReferences) {
    switch (eReferences.size()) {
    case 0:
        return null;
    case 1:
        return eReferences.get(0);
    default:
        return new SingleElementListSelectionDialog<EReference>(shell, new LabelProvider() {
            @Override
            public String getText(Object element) {
                return ((EReference) element).getName();
            }

            //                  @Override
            //                  public Image getImage(Object element) {
            //                     return IconUtil.getIcon("edge18.png");
            //                  }
        }, eReferences.toArray(new EReference[eReferences.size()]), "Edge Type Selection",
                "Select a EReference for the new edge type:").run();
    }
}