Exemplo n.º 1
0
  @Override
  public void createPartControl(Composite parent) {
    viewer = new GraphViewer(parent, SWT.NONE);
    viewer.setContentProvider(new ViewContentProvider());
    viewer.setLabelProvider(new ViewLabelProvider());
    viewer.setInput(getViewSite());
    viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING));
    ResourcesPlugin.getWorkspace()
        .addResourceChangeListener(
            new IResourceChangeListener() {
              public void resourceChanged(IResourceChangeEvent event) {
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {
                          public void run() {
                            viewer.refresh();
                            viewer.applyLayout();
                          }
                        });
              }
            });
    getSite().setSelectionProvider(viewer);

    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(viewer.getControl(), "com.javadude.dependencies2.viewer");
  }
Exemplo n.º 2
0
 private void testWith(IGraphContentProvider contentProvider) {
   viewer.setContentProvider(contentProvider);
   viewer.setLabelProvider(new CustomLabelProvider());
   viewer.setInput(new Object());
   StringBuffer buffer = new StringBuffer();
   for (int i = 0; i < viewer.getGraphControl().getNodes().size(); i++) {
     CGraphNode n = (CGraphNode) viewer.getGraphControl().getNodes().get(i);
     buffer.append(((Label) n.getNodeFigure().getChildren().get(0)).getText());
   }
   String string = buffer.toString();
   assertTrue("Label 1 should be in figure labels", string.indexOf("1") >= 0);
   assertTrue("Label 2 should be in figure labels", string.indexOf("2") >= 0);
   assertTrue("Label 3 should be in figure labels", string.indexOf("3") >= 0);
 }