private void createSchemaGui(final TabFolder tabFolder, final SchemaTree schemaTreeModel) {
   final TabItem dbStructureTabItem = new TabItem(tabFolder, SWT.NULL);
   dbStructureTabItem.setText("Database Structure");
   final Tree tree = new Tree(tabFolder, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
   tree.setHeaderVisible(true);
   tree.setLinesVisible(true);
   tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
   // create the jface wrapper
   final TreeViewer treeViewer = new TreeViewer(tree);
   final String[] schemaColumnNames = new String[] {"Name", "Object", "Type", "Schema"};
   final int[] schemaColumnWidths = new int[] {200, 100, 150, 800};
   final int[] schemaColumnAlignments = new int[] {SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT};
   for (int i = 0; i < schemaColumnNames.length; i++) {
     final TreeColumn treeColumn = new TreeColumn(tree, schemaColumnAlignments[i]);
     treeColumn.setText(schemaColumnNames[i]);
     treeColumn.pack();
     treeColumn.setWidth(schemaColumnWidths[i]);
   }
   final SchemaContentProvider schemaContentProvider = new SchemaContentProvider();
   treeViewer.setContentProvider(schemaContentProvider);
   treeViewer.setLabelProvider(new SchemaLabelProvider());
   treeViewer.setInput(schemaTreeModel.getRoot());
   // Add table viewer to database structure tab item
   dbStructureTabItem.setControl(tree);
 }
  private void createTaskTree(Composite parent) {
    PatternFilter filter = new PatternFilter();
    FilteredTree filteredTree =
        new FilteredTree(parent, SWT.CHECK | SWT.BORDER, filter, true) {
          @Override
          protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
            return new ContainerCheckedTreeViewer(parent, style);
          }
        };
    taskSelectionTreeViewer = (CheckboxTreeViewer) filteredTree.getViewer();
    filteredTree.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Add multi column support
    Tree tree = taskSelectionTreeViewer.getTree();
    tree.setHeaderVisible(true);
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Project/Task");
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Description");
    column1.pack();
    column2.pack();

    taskSelectionTreeViewer.setLabelProvider(new GradleTaskTreeLabelProvider());
    taskSelectionTreeViewer.setContentProvider(
        new GradleTaskTreeContentProvider(taskSelectionTreeViewer, true));
    taskSelectionTreeViewer.setCheckStateProvider(tasksChecked);
    taskSelectionTreeViewer.addCheckStateListener(tasksChecked);

    if (project != null) {
      setTreeInput(project);
    }
  }
  /**
   * DOC chuang Comment method "createTreeTableView".
   *
   * @param parent
   */
  private void createTreeTableViewer(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout());
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer =
        new TreeViewer(composite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    // init tree
    final Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));

    // create tree column
    TreeColumn column = new TreeColumn(tree, SWT.NONE);
    column.setText("Resource"); // $NON-NLS-1$
    column.setWidth(150);

    column = new TreeColumn(tree, SWT.NONE);
    column.setText("Description"); // $NON-NLS-1$
    column.setWidth(300);

    viewer.setContentProvider(new ErrorDetailContentProvider());
    viewer.setLabelProvider(new ErrorDetailLabelProvider());
    viewer.setInput(errors);
    viewer.expandAll();
  }
Пример #4
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets .Composite)
   */
  @Override
  public void createPartControl(final Composite parent) {
    final Tree variableTree = new Tree(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    variableTree.setHeaderVisible(true);
    viewer = new TreeViewer(variableTree);

    final TreeColumn column1 = new TreeColumn(variableTree, SWT.LEFT);
    variableTree.setLinesVisible(true);
    column1.setAlignment(SWT.LEFT);
    column1.setText("Variable-Name");
    column1.setWidth(130);
    final TreeColumn column2 = new TreeColumn(variableTree, SWT.RIGHT);
    column2.setAlignment(SWT.LEFT);
    column2.setText("Assignment");
    column2.setWidth(130);

    viewer.expandAll();

    contProv = new VariableAssignmentContentProvider();
    viewer.setContentProvider(contProv);
    // we have to define an own label provider
    viewer.setLabelProvider(new VariableAssignmentLabelProvider());
    // we add this object as selection listener
    getViewSite().getPage().addSelectionListener(this);
  }
  /**
   * Create the composite.
   *
   * @param parent The parent reference.
   * @param menuService The menu service reference.
   */
  @PostConstruct
  public void createComposite(Composite parent, EMenuService menuService) {
    final Listener listener = UtilSwt.createAutosizeListener();
    properties = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    properties.setLayout(new FillLayout());
    properties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    properties.setHeaderVisible(true);
    properties.addListener(SWT.Collapse, listener);
    properties.addListener(SWT.Expand, listener);

    final TreeColumn key = new TreeColumn(properties, SWT.LEFT);
    key.setText(Messages.Properties_Key);

    final TreeColumn property = new TreeColumn(properties, SWT.LEFT);
    properties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    property.setText(Messages.Properties_Value);

    addListeners(menuService);
    PropertiesModel.INSTANCE.setTree(properties);

    providersObject =
        checkPropertiesExtensionPoint(
            PropertiesProviderObject.class,
            PropertiesProviderObject.EXTENSION_ID,
            PropertiesProviderObject.EXTENSION_PROPERTIES);
    providersTile =
        checkPropertiesExtensionPoint(
            PropertiesProviderTile.class,
            PropertiesProviderTile.EXTENSION_ID,
            PropertiesProviderTile.EXTENSION_PROPERTIES);
  }
  /**
   * Sets up tree columns.
   *
   * <p>Conveniently located here to keep column semantics in one place
   *
   * @param tv the tree viewer
   */
  public void configureTreeColumns(final TreeViewer tv) {

    final Tree tree = tv.getTree();

    TreeColumn c1 = new TreeColumn(tree, SWT.NONE);
    c1.setWidth(450);
    c1.setText("Name");

    tree.setHeaderVisible(true);

    tree.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mouseDoubleClick(MouseEvent e) {
            TreeItem item = tree.getItem(new Point(e.x, e.y));
            if (item != null) {
              boolean expanded = tv.getExpandedState(item.getData());
              if (expanded) {
                tv.collapseToLevel(item.getData(), 1);
              } else {
                tv.expandToLevel(item.getData(), 1);
              }
            }
          }
        });
  }
Пример #7
0
  /**
   * Creates the view.
   *
   * @param root
   */
  private void create(final Composite root) {

    root.setLayout(new FillLayout());

    Tree tree = new Tree(root, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    tree.setHeaderVisible(true);

    treeViewer = new TreeViewer(tree);
    tree.setMenu(new ClipboardHandlerTree(treeViewer).getMenu());

    final TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    tree.setLinesVisible(true);
    column1.setAlignment(SWT.LEFT);
    column1.setText(Resources.getMessage("PropertiesView.3")); // $NON-NLS-1$
    column1.setWidth(160);
    final TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT);
    column2.setAlignment(SWT.LEFT);
    column2.setText(Resources.getMessage("PropertiesView.4")); // $NON-NLS-1$
    column2.setWidth(100);
    final TreeColumn column6 = new TreeColumn(tree, SWT.RIGHT);
    column6.setAlignment(SWT.LEFT);
    column6.setText(Resources.getMessage("PropertiesView.5")); // $NON-NLS-1$
    column6.setWidth(100);
    final TreeColumn column7 = new TreeColumn(tree, SWT.RIGHT);
    column7.setAlignment(SWT.LEFT);
    column7.setText(Resources.getMessage("PropertiesView.101")); // $NON-NLS-1$
    column7.setWidth(80);
    final TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
    column3.setAlignment(SWT.LEFT);
    column3.setText(Resources.getMessage("PropertiesView.6")); // $NON-NLS-1$
    column3.setWidth(50);
    final TreeColumn column4 = new TreeColumn(tree, SWT.RIGHT);
    column4.setAlignment(SWT.LEFT);
    column4.setText(Resources.getMessage("PropertiesView.7")); // $NON-NLS-1$
    column4.setWidth(50);
    final TreeColumn column5 = new TreeColumn(tree, SWT.RIGHT);
    column5.setAlignment(SWT.LEFT);
    column5.setText(Resources.getMessage("PropertiesView.8")); // $NON-NLS-1$
    column5.setWidth(50);
    final TreeColumn column8 = new TreeColumn(tree, SWT.RIGHT);
    column8.setAlignment(SWT.LEFT);
    column8.setText(Resources.getMessage("PropertiesView.113")); // $NON-NLS-1$
    column8.setWidth(50);
    final TreeColumn column9 = new TreeColumn(tree, SWT.RIGHT);
    column9.setAlignment(SWT.LEFT);
    column9.setText(Resources.getMessage("PropertiesView.126")); // $NON-NLS-1$
    column9.setWidth(50);

    treeViewer.setContentProvider(new InputContentProvider());
    treeViewer.setLabelProvider(new InputLabelProvider());

    treeViewer.setInput(roots);
    treeViewer.expandAll();
  }
Пример #8
0
  /**
   * Configure the table.
   *
   * @param tree The tree
   */
  private void configureTree(Tree tree) {
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);

    for (MBeanAttributeColumn column : MBeanAttributeColumn.values()) {
      TreeColumn treeColumn = new TreeColumn(tree, SWT.NONE);
      treeColumn.setText(column.label);
      treeColumn.setWidth(column.defalutWidth);
      treeColumn.setAlignment(column.alignment);
      treeColumn.setToolTipText(column.toolTip);
    }
  }
  @Override
  public Composite createControl(Composite parent) {

    Tree tree =
        new Tree(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    tree.setHeaderVisible(true);
    fViewer = new TreeViewer(tree);
    ColumnViewerToolTipSupport.enableFor(fViewer);
    fColumnAdvisor = new RteValidateColumnAdvisor(fViewer);

    TreeViewerColumn column0 = new TreeViewerColumn(fViewer, SWT.LEFT);
    tree.setLinesVisible(true);
    column0.getColumn().setAlignment(SWT.LEFT);
    column0.getColumn().setText(CpStringsUI.RteValidateWidget_ValidationOutput);
    column0.getColumn().setWidth(400);
    column0.setEditingSupport(new AdvisedEditingSupport(fViewer, fColumnAdvisor, 0));

    fViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            handleTreeSelectionChanged(event);
          }
        });

    AdvisedCellLabelProvider col0LabelProvider = new AdvisedCellLabelProvider(fColumnAdvisor, 0);
    // workaround jface bug: first owner-draw column is not correctly painted when column is resized
    col0LabelProvider.setOwnerDrawEnabled(false);
    column0.setLabelProvider(col0LabelProvider);

    TreeViewerColumn column1 = new TreeViewerColumn(fViewer, SWT.RIGHT);
    column1.getColumn().setAlignment(SWT.LEFT);
    column1.getColumn().setText(CpStringsUI.RteValidateWidget_Description);
    column1.getColumn().setWidth(500);
    column1.setEditingSupport(new AdvisedEditingSupport(fViewer, fColumnAdvisor, 1));
    column1.setLabelProvider(new AdvisedCellLabelProvider(fColumnAdvisor, 1));

    RteValidateContentProvider validateProvider = new RteValidateContentProvider();
    fViewer.setContentProvider(validateProvider);

    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.verticalAlignment = SWT.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    tree.setLayoutData(gridData);

    if (getModelController() != null) {
      fViewer.setInput(getModelController());
    }
    return tree;
  }
Пример #10
0
  @Override
  public void create() {
    super.create();

    Label descriptionLabel = new Label(getDialogArea(), SWT.WRAP);
    descriptionLabel.setText(
        "Some local profiles have changed. Select the ones you want to re-apply");

    TreeViewer viewer = new TreeViewer(getDialogArea());
    viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Tree tree = viewer.getTree();

    TableLayout layout = new TableLayout();

    TreeColumn propertyColumn = new TreeColumn(tree, SWT.CENTER);
    propertyColumn.setText("Package");
    layout.addColumnData(new ColumnWeightData(30, 300, true));

    TreeColumn propertyVersionColumn = new TreeColumn(tree, SWT.CENTER);
    propertyVersionColumn.setText("Version");
    layout.addColumnData(new ColumnWeightData(30, 100, true));

    TreeColumn ownerColumn = new TreeColumn(tree, SWT.CENTER);
    ownerColumn.setText("Profile");
    layout.addColumnData(new ColumnWeightData(60, 150, true));

    TreeColumn ownerVersionColumn = new TreeColumn(tree, SWT.CENTER);
    ownerVersionColumn.setText("Version");
    layout.addColumnData(new ColumnWeightData(30, 100, true));

    TreeColumn checkColumn = new TreeColumn(tree, SWT.CENTER);
    checkColumn.setText("Reapply");
    layout.addColumnData(new ColumnWeightData(10, 70, true));

    tree.setLayout(layout);
    tree.setHeaderVisible(true);

    viewer.setContentProvider(new ProfileApplicationContentProvider(rootPackage));
    viewer.setLabelProvider(new ProfileApplicationLabelProvider());

    viewer.setInput(new Object());

    installEditors(viewer);

    getDialogArea().layout();

    getShell().pack();
  }
Пример #11
0
  private void createColumns(TreeColumn[] currentColumns, int[] widths) {
    Tree tree = this.viewer.getTree();
    TableLayout layout = new TableLayout();

    TreeViewerColumn column = null;
    layout.addColumnData(new ColumnPixelData(440, true, true));
    column = new TreeViewerColumn(this.viewer, 0);
    column.setLabelProvider(new MarkerColumnLabelProvider());
    column.getColumn().setText("breakpoints");

    this.viewer.getTree().setLayout(layout);
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    tree.layout(true);
  }
Пример #12
0
  public SnippetTreeTableRidget006(final Shell shell) {
    final Composite tableComposite = new Composite(shell, SWT.NONE);
    tableComposite.setLayout(new GridLayout());
    final GridData layoutData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableComposite.setLayoutData(layoutData2);

    final Tree tree = new Tree(tableComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
    final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.heightHint = 100;
    tree.setLayoutData(layoutData);
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);

    final TreeColumnLayout columnLayout = new TreeColumnLayout();
    final TreeColumn tableColumn = new TreeColumn(tree, SWT.FILL);
    tableColumn.setText("Test");
    columnLayout.setColumnData(tableColumn, new ColumnWeightData(10, 100));
    tableComposite.setLayout(columnLayout);

    final ITreeTableRidget treeRiget = (ITreeTableRidget) SwtRidgetFactory.createRidget(tree);
    treeRiget.setSelectionType(ISelectableRidget.SelectionType.MULTI);

    treeRiget.setColumnFormatter(
        0,
        new ColumnFormatter() {
          @Override
          public String getText(final Object element) {
            final TestTreeNode node = (TestTreeNode) element;
            if (node.getName() == null) {
              return "";
            }
            return node.getName();
          }
        });

    final Object[] roots = new Object[] {new TestTreeNode(null), new TestTreeNode("name")};
    treeRiget.bindToModel(
        roots,
        TestTreeNode.class,
        "children",
        "parent",
        new String[] {"name"},
        new String[] {"Name"});
  }
Пример #13
0
  private void createBrowseLocalFilesView(FormToolkit toolkit, Composite parent) {
    Section localFilesSection =
        toolkit.createSection(parent, Section.TITLE_BAR | Section.DESCRIPTION);

    localFilesSection.setText("Local Files");
    localFilesSection.setDescription("Double click to add to current project");

    Composite composite = toolkit.createComposite(localFilesSection, SWT.WRAP);
    composite.setBounds(10, 94, 64, 64);

    FormData fd_composite = new FormData();
    fd_composite.bottom = new FormAttachment(100, -10);
    fd_composite.right = new FormAttachment(0, 751);
    fd_composite.left = new FormAttachment(0, 10);
    composite.setLayoutData(fd_composite);
    composite.setLayout(new TreeColumnLayout());

    treeViewer = new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    Tree localFilesTree = treeViewer.getTree();
    localFilesTree.setHeaderVisible(true);
    localFilesTree.setLinesVisible(true);

    treeViewer.setAutoExpandLevel(2);

    drillDownAdapter = new DrillDownAdapter(treeViewer);

    treeViewer.setContentProvider(new ViewContentProvider());

    treeViewer.setLabelProvider(new ViewLabelProvider());

    treeViewer.setSorter(new NameSorter());
    treeViewer.setInput(File.listRoots());

    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(treeViewer.getControl(), "com.plugin.tryplugin.viewer");

    makeActions();
    hookContextMenu();
    hookDoubleClickAction();
    contributeToActionBars();
    localFilesSection.setClient(composite);
  }
  protected void createTreeArea() {

    tvInfos = new TreeViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
    Tree tree = tvInfos.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    final GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_tree.heightHint = 120;
    gd_tree.minimumHeight = 80;
    tree.setLayoutData(gd_tree);
    tvInfos.setContentProvider(new ListContentProvider());
    tvInfos.setLabelProvider(getLabelProviderForViewer());
    tvInfos.setColumnProperties(getColumnProperties());
    tvInfos.setCellEditors(getCellEditors());
    tvInfos.setCellModifier(getCellModifier());

    tvInfos.setInput(getInfos());

    fillColumnsInTree(tree);
  }
  public void createPartControl(Composite parent) {
    viewer = new TreeViewer(parent, SWT.NONE);

    Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);

    TreeColumn col1 = new TreeColumn(tree, SWT.NONE);
    col1.setText("Parameter name");
    col1.setWidth(150);

    TreeColumn col2 = new TreeColumn(tree, SWT.NONE);
    col2.setText("Value");
    col2.setWidth(150);

    viewer.setContentProvider(new NodeInfoViewContentProvider());
    viewer.setLabelProvider(new NodeInfoViewLabelProvider());
    viewer.setAutoExpandLevel(3);
    viewer.setInput(null);

    getSite().getPage().addSelectionListener(this);
  }
Пример #16
0
 public void createPartControl(Composite parent) {
   this.setPartName(
       "DataManagement[" + ServerManager.getInstance().getServer(serverId).getName() + "]");
   parent.setLayout(new GridLayout(1, true));
   labelComp = new Composite(parent, SWT.NONE);
   labelComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
   labelComp.setLayout(new RowLayout());
   totalLabel = new Label(parent, SWT.NONE);
   totalLabel.setText("                                                ");
   Composite treeComp = new Composite(parent, SWT.BORDER);
   treeComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
   tree = new Tree(treeComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
   tree.setHeaderVisible(true);
   viewer = new TreeViewer(tree);
   tree.setLinesVisible(true);
   final TreeColumn nameColumn = new TreeColumn(tree, SWT.LEFT);
   nameColumn.setAlignment(SWT.LEFT);
   nameColumn.setText("Name");
   nameColumn.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           TreeLabelSorter sorter = (TreeLabelSorter) viewer.getComparator();
           sorter.setColumn(nameColumn);
         }
       });
   final TreeColumn sizeColumn = new TreeColumn(tree, SWT.RIGHT);
   sizeColumn.setAlignment(SWT.RIGHT);
   sizeColumn.setText("Size");
   sizeColumn.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           TreeLabelSorter sorter = (TreeLabelSorter) viewer.getComparator();
           sorter.setColumn(sizeColumn);
         }
       });
   final TreeColumn timeColumn = new TreeColumn(tree, SWT.CENTER);
   timeColumn.setAlignment(SWT.CENTER);
   timeColumn.setText("Last Modified");
   timeColumn.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           TreeLabelSorter sorter = (TreeLabelSorter) viewer.getComparator();
           sorter.setColumn(timeColumn);
         }
       });
   TreeColumnLayout layout = new TreeColumnLayout();
   treeComp.setLayout(layout);
   layout.setColumnData(nameColumn, new ColumnWeightData(30));
   layout.setColumnData(sizeColumn, new ColumnWeightData(20));
   layout.setColumnData(timeColumn, new ColumnWeightData(20));
   viewer.setContentProvider(new DirContentProvider());
   viewer.setLabelProvider(new LockLabelProvider());
   viewer.setComparator(
       new TreeLabelSorter(viewer)
           .setCustomCompare(
               new TreeLabelSorter.ICustomCompare() {
                 public int doCompare(TreeColumn col, int index, Object o1, Object o2) {
                   if (o1 instanceof DirObject && o2 instanceof DirObject) {
                     DirObject dirObj1 = (DirObject) o1;
                     DirObject dirObj2 = (DirObject) o2;
                     switch (index) {
                       case 0:
                         return dirObj1.name.compareTo(dirObj2.name);
                       case 1:
                         long gap = dirObj1.size - dirObj2.size;
                         if (gap > 0) {
                           return 1;
                         } else if (gap < 0) {
                           return -1;
                         } else {
                           return 0;
                         }
                       case 2:
                         gap = dirObj1.lastModified - dirObj2.lastModified;
                         if (gap > 0) {
                           return 1;
                         } else if (gap < 0) {
                           return -1;
                         } else {
                           return 0;
                         }
                     }
                   }
                   return 0;
                 }
               }));
   viewer.setInput(dirMap);
   IToolBarManager man = getViewSite().getActionBars().getToolBarManager();
   man.add(
       new Action("Collapse All", ImageUtil.getImageDescriptor(Images.collapse)) {
         public void run() {
           viewer.collapseAll();
         }
       });
   man.add(new Separator());
   man.add(
       new Action("Reload", ImageUtil.getImageDescriptor(Images.refresh)) {
         public void run() {
           load();
         }
       });
   load();
   createContextMenu(
       viewer,
       new IMenuListener() {
         public void menuAboutToShow(IMenuManager manager) {
           fillTreeViewerContextMenu(manager);
         }
       });
 }
Пример #17
0
  // --------------------------------------------------------------------------------
  public void init2() {
    parent.setLayout(new FormLayout());

    sashForm = new SashForm(parent, SWT.SMOOTH | SWT.VERTICAL);
    FormData fd_sashForm1 = new FormData();
    fd_sashForm1.top = new FormAttachment(0, 1);
    fd_sashForm1.left = new FormAttachment(0, 1);
    fd_sashForm1.right = new FormAttachment(100, -1);
    fd_sashForm1.bottom = new FormAttachment(100, -1);
    sashForm.setLayoutData(fd_sashForm1);

    tree = new Tree(sashForm, SWT.BORDER | SWT.FULL_SELECTION);
    tree.setHeaderVisible(true);

    FormData d1 = new FormData();
    d1.top = new FormAttachment(0, 1);
    d1.left = new FormAttachment(0, 1);
    d1.right = new FormAttachment(100, -1);
    d1.bottom = new FormAttachment(100, -1);
    tree.setLayoutData(d1);

    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Data Type");

    editorComposite = new Composite(sashForm, SWT.BORDER);
    editorComposite.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent e) {
            onSashResize();
          }
        });

    FormData fd_composite1 = new FormData();
    fd_composite1.top = new FormAttachment(0, 1);
    fd_composite1.bottom = new FormAttachment(0, 35);
    fd_composite1.right = new FormAttachment(100, -1);
    fd_composite1.left = new FormAttachment(0, 1);
    editorComposite.setLayoutData(fd_composite1);
    editorComposite.setLayout(new FormLayout());
    Label nameLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_nameLabel = new FormData();
    fd_nameLabel.right = new FormAttachment(0, 66);
    fd_nameLabel.bottom = new FormAttachment(0, 32);
    fd_nameLabel.top = new FormAttachment(0, 12);
    fd_nameLabel.left = new FormAttachment(0, 10);
    nameLabel.setLayoutData(fd_nameLabel);
    nameLabel.setText("Name :");
    Label valueLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_valueLabel = new FormData();
    fd_valueLabel.top = new FormAttachment(nameLabel, 15);
    fd_valueLabel.left = new FormAttachment(0, 10);
    fd_valueLabel.bottom = new FormAttachment(nameLabel, 34, SWT.BOTTOM);
    fd_valueLabel.right = new FormAttachment(nameLabel, 0, SWT.RIGHT);
    valueLabel.setLayoutData(fd_valueLabel);
    valueLabel.setText("Value :");

    valueText =
        new Text(
            editorComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI);
    valueText.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            verifyData();
          }
        });
    valueText.setEnabled(false);
    valueText.setEditable(false);
    FormData fd_valueText = new FormData();
    fd_valueText.top = new FormAttachment(nameLabel, 5);
    fd_valueText.bottom = new FormAttachment(100, -80);
    fd_valueText.right = new FormAttachment(100, -20);
    fd_valueText.left = new FormAttachment(valueLabel, 0, SWT.RIGHT);
    valueText.setLayoutData(fd_valueText);

    updateButton = new Button(editorComposite, SWT.NONE);
    updateButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            onUpdateButtonSelect();
          }
        });
    updateButton.setEnabled(false);
    FormData fd_updateButton = new FormData();
    fd_updateButton.left = new FormAttachment(100, -120);
    fd_updateButton.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    updateButton.setLayoutData(fd_updateButton);
    updateButton.setText("Update");

    typeCombo = new Combo(editorComposite, SWT.READ_ONLY);
    fd_updateButton.top = new FormAttachment(typeCombo, 10);
    typeCombo.setEnabled(false);
    FormData fd_typeList = new FormData();
    fd_typeList.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_typeList.top = new FormAttachment(valueText, 5, SWT.BOTTOM);
    // fd_typeList.bottom = new FormAttachment(valueText, 30, SWT.BOTTOM);
    fd_typeList.right = new FormAttachment(valueText, 170, SWT.LEFT);
    typeCombo.setLayoutData(fd_typeList);

    typeCombo.add("Double");
    typeCombo.add("Integer");
    typeCombo.add("Long");
    typeCombo.add("String");
    typeCombo.add("List (BasicDBList)");
    typeCombo.add("Map (BasicDBObject)");
    typeCombo.add("Date");
    typeCombo.add("ObjectId");
    typeCombo.add("JavaScript code");
    typeCombo.add("Binary data");
    typeCombo.add("Boolean");
    typeCombo.add("Null");
    typeCombo.add("Regular expression");
    typeCombo.add("Symbol");
    typeCombo.add("JavaScript code with scope");
    typeCombo.add("Timestamp");
    typeCombo.add("Min key");
    typeCombo.add("Max key");

    typeCombo.addListener(SWT.Selection, this);

    typeComboIndexMap.put(Double.class, new Integer(0));
    typeComboIndexMap.put(Integer.class, new Integer(1));
    typeComboIndexMap.put(Long.class, new Integer(2));
    typeComboIndexMap.put(String.class, new Integer(3));
    typeComboIndexMap.put(com.mongodb.BasicDBList.class, new Integer(4));
    typeComboIndexMap.put(com.mongodb.BasicDBObject.class, new Integer(5));
    typeComboIndexMap.put(java.util.Date.class, new Integer(6));
    typeComboIndexMap.put(org.bson.types.ObjectId.class, new Integer(7));
    typeComboIndexMap.put(org.bson.types.Code.class, new Integer(8));
    typeComboIndexMap.put(byte[].class, new Integer(9));
    typeComboIndexMap.put(Boolean.class, new Integer(10));
    typeComboIndexMap.put(java.util.regex.Pattern.class, new Integer(12));
    typeComboIndexMap.put(org.bson.types.Symbol.class, new Integer(13));
    typeComboIndexMap.put(org.bson.types.CodeWScope.class, new Integer(14));
    typeComboIndexMap.put(org.bson.types.BSONTimestamp.class, new Integer(15));
    typeComboIndexMap.put(org.bson.types.MinKey.class, new Integer(16));
    typeComboIndexMap.put(org.bson.types.MaxKey.class, new Integer(17));

    Label typeLabel = new Label(editorComposite, SWT.NONE);
    FormData fd_typeLabel = new FormData();
    fd_typeLabel.top = new FormAttachment(typeCombo, 3, SWT.TOP);
    fd_typeLabel.left = new FormAttachment(nameLabel, 0, SWT.LEFT);
    typeLabel.setLayoutData(fd_typeLabel);
    typeLabel.setText("Type :");

    nameText = new Text(editorComposite, SWT.READ_ONLY);
    nameText.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
    FormData fd_nameText = new FormData();
    fd_nameText.top = new FormAttachment(nameLabel, -2, SWT.TOP);
    fd_nameText.left = new FormAttachment(valueText, 0, SWT.LEFT);
    fd_nameText.right = new FormAttachment(valueText, 0, SWT.RIGHT);
    nameText.setLayoutData(fd_nameText);

    MSwtUtil.getTreeColumnWidthFromProperties("documentTree", tree, prop, new int[] {150, 150});

    // listeners
    tree.addListener(SWT.MouseDoubleClick, this);
    tree.addListener(SWT.Selection, this);
    tree.addListener(SWT.KeyDown, this);
    MSwtUtil.addListenerToTreeColumns2(tree, this);

    documentImage = MUtil.getImage(parent.getShell().getDisplay(), "table.png");
    oidImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_star.png");
    intImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_blue.png");
    longImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_red.png");
    doubleImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_orange.png");
    stringImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_green.png");
    dateImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_white.png");
    boolImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_yellow.png");
    listImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_blue.png");
    mapImage = MUtil.getImage(parent.getShell().getDisplay(), "stop_green.png");
    nullImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_black.png");
    jsImage = MUtil.getImage(parent.getShell().getDisplay(), "bullet_right.png");

    if (prop.containsKey(DOCUMENT_COMPOSITE_WEIGHT)) {

      (new Thread() {
            public void run() {
              // System.out.println( "e" );
              MSystemUtil.sleep(0);
              // System.out.println( "a" );
              shell
                  .getDisplay()
                  .asyncExec(
                      new Runnable() {
                        public void run() { // ----
                          // debug( "--" + prop.getIntArrayProperty( DOCUMENT_COMPOSITE_WEIGHT )[ 0
                          // ] );
                          sashForm.setWeights(prop.getIntArrayProperty(DOCUMENT_COMPOSITE_WEIGHT));
                        }
                      }); // ----
            }
          })
          .start();

    } else {
      sashForm.setWeights(new int[] {70, 30});
    }
    initializedTime = System.currentTimeMillis();
  }
  @Override
  public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    composite.setLayout(new GridLayout(3, false));

    Label lblName = new Label(composite, SWT.NONE);
    lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblName.setText("Name Filter"); // $NON-NLS-1$

    textFilter = new Text(composite, SWT.BORDER);
    textFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    textFilter.addKeyListener(
        new KeyAdapter() {
          public void keyReleased(KeyEvent e) {
            filter.setSearchString(textFilter.getText());
            treeViewerCollections.refresh();
          }
        });

    Button btnRefresh = new Button(composite, SWT.NONE);
    btnRefresh.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            initData();
          }
        });
    btnRefresh.setText("Refresh"); // $NON-NLS-1$

    Composite compositeBody = new Composite(parent, SWT.NONE);
    compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    compositeBody.setLayout(new GridLayout(1, false));

    treeViewerCollections = new TreeViewer(compositeBody, SWT.BORDER);
    treeViewerCollections.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            try {

              IStructuredSelection is = (IStructuredSelection) event.getSelection();
              Object selElement = is.getFirstElement();

              if (selElement instanceof MongoDBCollectionInfoDTO) {
                MongoDBCollectionInfoDTO dto = (MongoDBCollectionInfoDTO) selElement;

                dto.setChild(MongoDBQuery.collectionColumn(userDB, dto.getName()));
                treeViewerCollections.refresh(dto, true);

                treeViewerCollections.expandToLevel(dto, 1);
              }
            } catch (Exception e) {
              logger.error("mongodb treeview refresh", e); // $NON-NLS-1$
            }
          }
        });
    treeViewerCollections.addDoubleClickListener(
        new IDoubleClickListener() {
          public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection is = (IStructuredSelection) event.getSelection();
            Object selElement = is.getFirstElement();

            if (selElement instanceof MongoDBCollectionInfoDTO) {
              MongoDBCollectionInfoDTO dto = (MongoDBCollectionInfoDTO) selElement;

              MongoDBEditorInput input =
                  new MongoDBEditorInput(dto.getName(), userDB, dto.getChild());
              IWorkbenchPage page =
                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
              try {
                page.openEditor(input, MongoDBTableEditor.ID);
              } catch (PartInitException e) {
                logger.error("Load the table data", e); // $NON-NLS-1$

                Status errStatus =
                    new Status(
                        IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$
                ExceptionDetailsErrorDialog.openError(
                    getSite().getShell(),
                    "Error",
                    "An error has occurred.",
                    errStatus); //$NON-NLS-1$ //$NON-NLS-2$
              }
            }
          }
        });
    Tree tree = treeViewerCollections.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    collectionSorter = new MongoDBCollectionComparator();
    createTableColumn();

    treeViewerCollections.setContentProvider(new MongoInfoContentProvider());
    treeViewerCollections.setLabelProvider(new MongoInfoLabelProvider());
    treeViewerCollections.setInput(collectionList);
    treeViewerCollections.setComparator(collectionSorter);

    filter = new MongoInfoFilter();
    treeViewerCollections.addFilter(filter);

    Group grpSummary = new Group(parent, SWT.NONE);
    grpSummary.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpSummary.setText("Summary"); // $NON-NLS-1$
    grpSummary.setLayout(new GridLayout(4, false));

    lblCollection = new Label(grpSummary, SWT.BORDER);
    lblCollection.setText("Collection"); // $NON-NLS-1$

    lblSizes = new Label(grpSummary, SWT.BORDER);
    lblSizes.setText("Sizes"); // $NON-NLS-1$

    lblStorages = new Label(grpSummary, SWT.BORDER);
    lblStorages.setText("Storages"); // $NON-NLS-1$

    lblIndex = new Label(grpSummary, SWT.BORDER);
    lblIndex.setText("Index"); // $NON-NLS-1$

    initData();
  }
  /**
   * This is the method used by the framework to install your own controls.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  public void createPages() {
    // Creates the model from the editor input
    //
    createModel();

    // Create a page for the selection tree view.
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              Tree tree = new Tree(composite, SWT.MULTI);
              TreeViewer newTreeViewer = new TreeViewer(tree);
              return newTreeViewer;
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());

      selectionViewer = (TreeViewer) viewerPane.getViewer();
      selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));

      selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
      selectionViewer.setInput(editingDomain.getResourceSet());
      viewerPane.setTitle(editingDomain.getResourceSet());

      new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);

      createContextMenuFor(selectionViewer);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_SelectionPage_label"));
    }

    // Create a page for the parent tree view.
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              Tree tree = new Tree(composite, SWT.MULTI);
              TreeViewer newTreeViewer = new TreeViewer(tree);
              return newTreeViewer;
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());

      parentViewer = (TreeViewer) viewerPane.getViewer();
      parentViewer.setAutoExpandLevel(30);
      parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
      parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));

      createContextMenuFor(parentViewer);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_ParentPage_label"));
    }

    // This is the page for the list viewer
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              return new ListViewer(composite);
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());
      listViewer = (ListViewer) viewerPane.getViewer();
      listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
      listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));

      createContextMenuFor(listViewer);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_ListPage_label"));
    }

    // This is the page for the tree viewer
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              return new TreeViewer(composite);
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());
      treeViewer = (TreeViewer) viewerPane.getViewer();
      treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
      treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));

      new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);

      createContextMenuFor(treeViewer);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_TreePage_label"));
    }

    // This is the page for the table viewer.
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              return new TableViewer(composite);
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());
      tableViewer = (TableViewer) viewerPane.getViewer();

      Table table = tableViewer.getTable();
      TableLayout layout = new TableLayout();
      table.setLayout(layout);
      table.setHeaderVisible(true);
      table.setLinesVisible(true);

      TableColumn objectColumn = new TableColumn(table, SWT.NONE);
      layout.addColumnData(new ColumnWeightData(3, 100, true));
      objectColumn.setText(getString("_UI_ObjectColumn_label"));
      objectColumn.setResizable(true);

      TableColumn selfColumn = new TableColumn(table, SWT.NONE);
      layout.addColumnData(new ColumnWeightData(2, 100, true));
      selfColumn.setText(getString("_UI_SelfColumn_label"));
      selfColumn.setResizable(true);

      tableViewer.setColumnProperties(new String[] {"a", "b"});
      tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
      tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));

      createContextMenuFor(tableViewer);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_TablePage_label"));
    }

    // This is the page for the table tree viewer.
    //
    {
      ViewerPane viewerPane =
          new ViewerPane(getSite().getPage(), ProvervisualEditor.this) {
            public Viewer createViewer(Composite composite) {
              return new TreeViewer(composite);
            }

            public void requestActivation() {
              super.requestActivation();
              setCurrentViewerPane(this);
            }
          };
      viewerPane.createControl(getContainer());

      treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();

      Tree tree = treeViewerWithColumns.getTree();
      tree.setLayoutData(new FillLayout());
      tree.setHeaderVisible(true);
      tree.setLinesVisible(true);

      TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
      objectColumn.setText(getString("_UI_ObjectColumn_label"));
      objectColumn.setResizable(true);
      objectColumn.setWidth(250);

      TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
      selfColumn.setText(getString("_UI_SelfColumn_label"));
      selfColumn.setResizable(true);
      selfColumn.setWidth(200);

      treeViewerWithColumns.setColumnProperties(new String[] {"a", "b"});
      treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
      treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));

      createContextMenuFor(treeViewerWithColumns);
      int pageIndex = addPage(viewerPane.getControl());
      setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
    }

    setActivePage(0);

    getContainer()
        .addControlListener(
            new ControlAdapter() {
              boolean guard = false;

              public void controlResized(ControlEvent event) {
                if (!guard) {
                  guard = true;
                  hideTabs();
                  guard = false;
                }
              }
            });
  }
Пример #20
0
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Custom gradient selection for Tree");
    shell.setLayout(new FillLayout());
    final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION);
    tree.setHeaderVisible(false);
    tree.setLinesVisible(false);
    int columnCount = 4;
    for (int i = 0; i < columnCount; i++) {
      TreeColumn column = new TreeColumn(tree, SWT.NONE);
      column.setText("Column " + i);
    }
    int itemCount = 3;
    for (int i = 0; i < itemCount; i++) {
      TreeItem item1 = new TreeItem(tree, SWT.NONE);
      item1.setText("item " + i);
      for (int c = 1; c < columnCount; c++) {
        item1.setText(c, "item [" + i + "-" + c + "]");
      }
      for (int j = 0; j < itemCount; j++) {
        TreeItem item2 = new TreeItem(item1, SWT.NONE);
        item2.setText("item [" + i + " " + j + "]");
        for (int c = 1; c < columnCount; c++) {
          item2.setText(c, "item [" + i + " " + j + "-" + c + "]");
        }
        for (int k = 0; k < itemCount; k++) {
          TreeItem item3 = new TreeItem(item2, SWT.NONE);
          item3.setText("item [" + i + " " + j + " " + k + "]");
          for (int c = 1; c < columnCount; c++) {
            item3.setText(c, "item [" + i + " " + j + " " + k + "-" + c + "]");
          }
        }
      }
    }

    /*
     * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly.
     * Therefore, it is critical for performance that these methods be
     * as efficient as possible.
     */
    tree.addListener(
        SWT.EraseItem,
        new Listener() {
          public void handleEvent(Event event) {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) != 0) {
              GC gc = event.gc;
              Rectangle area = tree.getClientArea();
              /*
               * If you wish to paint the selection beyond the end of
               * last column, you must change the clipping region.
               */
              int columnCount = tree.getColumnCount();
              if (event.index == columnCount - 1 || columnCount == 0) {
                int width = area.x + area.width - event.x;
                if (width > 0) {
                  Region region = new Region();
                  gc.getClipping(region);
                  region.add(event.x, event.y, width, event.height);
                  gc.setClipping(region);
                  region.dispose();
                }
              }
              gc.setAdvanced(true);
              if (gc.getAdvanced()) gc.setAlpha(127);
              Rectangle rect = event.getBounds();
              Color foreground = gc.getForeground();
              Color background = gc.getBackground();
              gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
              gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
              gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
              // restore colors for subsequent drawing
              gc.setForeground(foreground);
              gc.setBackground(background);
              event.detail &= ~SWT.SELECTED;
            }
          }
        });
    for (int i = 0; i < columnCount; i++) {
      tree.getColumn(i).pack();
    }
    tree.setSelection(tree.getItem(0));
    shell.setSize(500, 200);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Пример #21
0
  private Section createFileSection(Composite container) {
    Section filesSection =
        toolkit.createSection(
            container, ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(filesSection);
    Composite filesArea = toolkit.createComposite(filesSection);
    filesSection.setClient(filesArea);
    toolkit.paintBordersFor(filesArea);
    GridLayoutFactory.fillDefaults().extendedMargins(2, 2, 2, 2).applyTo(filesArea);

    ToolBar filesToolbar = new ToolBar(filesSection, SWT.FLAT);

    filesSection.setTextClient(filesToolbar);

    PatternFilter patternFilter =
        new PatternFilter() {
          @Override
          protected boolean isLeafMatch(Viewer viewer, Object element) {
            if (element instanceof CommitItem) {
              CommitItem commitItem = (CommitItem) element;
              return wordMatches(commitItem.path);
            }
            return super.isLeafMatch(viewer, element);
          }
        };
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredCheckboxTree resourcesTreeComposite =
        new FilteredCheckboxTree(filesArea, toolkit, SWT.FULL_SELECTION, patternFilter) {
          @Override
          protected WorkbenchJob doCreateRefreshJob() {
            // workaround for file filter not having an explicit change
            // listener
            WorkbenchJob filterJob = super.doCreateRefreshJob();
            filterJob.addJobChangeListener(
                new JobChangeAdapter() {
                  public void done(IJobChangeEvent event) {
                    if (event.getResult().isOK()) {
                      getDisplay()
                          .asyncExec(
                              new Runnable() {
                                public void run() {
                                  updateFileSectionText();
                                }
                              });
                    }
                  }
                });
            return filterJob;
          }
        };
    Tree resourcesTree = resourcesTreeComposite.getViewer().getTree();
    resourcesTree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
    resourcesTreeComposite.setLayoutData(
        GridDataFactory.fillDefaults().hint(600, 200).grab(true, true).create());

    resourcesTree.addSelectionListener(new CommitItemSelectionListener());

    resourcesTree.setHeaderVisible(true);
    TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
    statCol.setText(UIText.CommitDialog_Status);
    statCol.setWidth(150);
    statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));

    TreeColumn resourceCol = new TreeColumn(resourcesTree, SWT.LEFT);
    resourceCol.setText(UIText.CommitDialog_Path);
    resourceCol.setWidth(415);
    resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));

    filesViewer = resourcesTreeComposite.getCheckboxTreeViewer();
    new TreeViewerColumn(filesViewer, statCol).setLabelProvider(createStatusLabelProvider());
    new TreeViewerColumn(filesViewer, resourceCol).setLabelProvider(new CommitPathLabelProvider());
    ColumnViewerToolTipSupport.enableFor(filesViewer);
    filesViewer.setContentProvider(new CommitFileContentProvider());
    filesViewer.setUseHashlookup(true);
    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    if (settings.get(SHOW_UNTRACKED_PREF) != null) {
      // note, no matter how the dialog settings are, if
      // the preferences force us to include untracked files
      // we must show them
      showUntracked =
          Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue()
              || getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
    }

    filesViewer.addFilter(new CommitItemFilter());
    filesViewer.setInput(items.toArray());
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(createContextMenuListener());
    filesViewer.getTree().setMenu(menuManager.createContextMenu(filesViewer.getTree()));
    filesViewer.addCheckStateListener(
        new ICheckStateListener() {

          public void checkStateChanged(CheckStateChangedEvent event) {
            updateFileSectionText();
          }
        });

    showUntrackedItem = new ToolItem(filesToolbar, SWT.CHECK);
    Image showUntrackedImage = UIIcons.UNTRACKED_FILE.createImage();
    UIUtils.hookDisposal(showUntrackedItem, showUntrackedImage);
    showUntrackedItem.setImage(showUntrackedImage);
    showUntrackedItem.setToolTipText(UIText.CommitDialog_ShowUntrackedFiles);
    showUntrackedItem.setSelection(showUntracked);
    showUntrackedItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            showUntracked = showUntrackedItem.getSelection();
            filesViewer.refresh(true);
            updateFileSectionText();
            updateMessage();
          }
        });

    ToolItem checkAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image checkImage = UIIcons.CHECK_ALL.createImage();
    UIUtils.hookDisposal(checkAllItem, checkImage);
    checkAllItem.setImage(checkImage);
    checkAllItem.setToolTipText(UIText.CommitDialog_SelectAll);
    checkAllItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(true);
            updateFileSectionText();
            updateMessage();
          }
        });

    ToolItem uncheckAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
    UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
    uncheckAllItem.setImage(uncheckImage);
    uncheckAllItem.setToolTipText(UIText.CommitDialog_DeselectAll);
    uncheckAllItem.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(false);
            updateFileSectionText();
            updateMessage();
          }
        });

    if (!allowToChangeSelection) {
      amendingItem.setSelection(false);
      amendingItem.setEnabled(false);
      showUntrackedItem.setSelection(false);
      showUntrackedItem.setEnabled(false);
      checkAllItem.setEnabled(false);
      uncheckAllItem.setEnabled(false);

      filesViewer.addCheckStateListener(
          new ICheckStateListener() {

            public void checkStateChanged(CheckStateChangedEvent event) {
              if (!event.getChecked()) filesViewer.setAllChecked(true);
              updateFileSectionText();
            }
          });
      filesViewer.setAllChecked(true);
    } else {
      final boolean includeUntracked =
          getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
      for (CommitItem item : items) {
        if (!preselectAll && !preselectedFiles.contains(item.path)) continue;
        if (item.status == Status.ASSUME_UNCHANGED) continue;
        if (!includeUntracked && item.status == Status.UNTRACKED) continue;
        filesViewer.setChecked(item, true);
      }
    }
    statCol.pack();
    resourceCol.pack();
    return filesSection;
  }
  @Override
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 3;
    // layout.verticalSpacing = 5;

    Label label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplateNewWizardPage_Project);
    projectText = new Text(container, SWT.BORDER | SWT.SINGLE);
    projectText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    projectText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            projectChanged();
          }
        });
    projectBrowse = new Button(container, SWT.PUSH);
    projectBrowse.setText(Messages.CmsisCodeTemplate_Browse);
    projectBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleProjectBrowse();
          }
        });

    fViewer =
        new TreeViewer(
            container, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Tree tree = fViewer.getTree();
    GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd_tree.heightHint = 300;
    tree.setLayoutData(gd_tree);
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    tree.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Object obj = e.item.getData();
            if (obj instanceof ICpCodeTemplate) {
              selectedCodeTemplate = (ICpCodeTemplate) obj;
              String[] codeTemplates = selectedCodeTemplate.getCodeTemplates();
              if (codeTemplates.length == 0) {
                fileText.setEditable(false);
                fileText.setText(CmsisConstants.EMPTY_STRING);
                return;
              }
              fileText.setEditable(true);
              StringBuilder sb = new StringBuilder(Utils.extractFileName(codeTemplates[0]));
              for (int i = 1; i < codeTemplates.length; i++) {
                fileText.setEditable(false);
                sb.append(' ');
                sb.append(Utils.extractFileName(codeTemplates[i]));
              }
              fileText.setText(sb.toString());
            }
          }
        });

    TreeViewerColumn column0 = new TreeViewerColumn(fViewer, SWT.LEFT);
    column0.getColumn().setText(Messages.CmsisCodeTemplate_Component);
    column0.getColumn().setWidth(200);
    column0.setLabelProvider(new ComponentColumnLabelProvider());

    TreeViewerColumn column1 = new TreeViewerColumn(fViewer, SWT.LEFT);
    column1.getColumn().setText(Messages.CmsisCodeTemplate_Name);
    column1.getColumn().setWidth(320);
    column1.setLabelProvider(new NameColumnLabelProvider());

    fViewer.setContentProvider(new CodeTemplateContentProvider());

    IRteProject rteProject = getRteProject();
    if (rteProject != null) {
      ICpCodeTemplate codeTemplate = rteProject.getRteConfiguration().getCmsisCodeTemplate();
      fViewer.setInput(codeTemplate);
      fViewer.getControl().setFocus();
    }

    label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplate_Location);
    containerText = new Text(container, SWT.BORDER | SWT.SINGLE);
    containerText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    containerText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            dialogChanged();
          }
        });
    containerBrowse = new Button(container, SWT.PUSH);
    containerBrowse.setText(Messages.CmsisCodeTemplate_Browse);
    containerBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleContainerBrowse();
          }
        });

    label = new Label(container, SWT.NULL);
    label.setText(Messages.CmsisCodeTemplate_FileName);
    fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
    fileText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fileText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            dialogChanged();
          }
        });

    initialize();
    projectChanged();
    setControl(container);
    new Label(container, SWT.NONE);
    PlatformUI.getWorkbench()
        .getHelpSystem()
        .setHelp(parent.getParent(), IHelpContextIds.CODE_TEMPLATE_WIZARD);
  }
Пример #23
0
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Tree tree = new Tree(shell, SWT.FULL_SELECTION | SWT.BORDER);
    tree.setHeaderVisible(true);
    TreeColumn column0 = new TreeColumn(tree, SWT.LEFT);
    column0.setText("Column 0");
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Column 1");
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Column 2");
    for (int i = 0; i < 9; i++) {
      TreeItem item = new TreeItem(tree, SWT.NONE);
      item.setText("item " + i);
      item.setText(1, "column 1 - " + i);
      item.setText(2, "column 2 - " + i);
      for (int j = 0; j < 9; j++) {
        TreeItem subItem = new TreeItem(item, SWT.NONE);
        subItem.setText("item " + i + " " + j);
        subItem.setText(1, "column 1 - " + i + " " + j);
        subItem.setText(2, "column 2 - " + i + " " + j);
        for (int k = 0; k < 9; k++) {
          TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
          subsubItem.setText("item " + i + " " + j + " " + k);
          subsubItem.setText(1, "column 1 - " + i + " " + j + " " + k);
          subsubItem.setText(2, "column 2 - " + i + " " + j + " " + k);
        }
      }
    }
    column0.pack();
    column1.pack();
    column2.pack();

    Heartbeat =
        new Runnable() {
          @Override
          public void run() {
            if (!Tracking || tree.isDisposed()) return;
            Point cursor = display.getCursorLocation();
            cursor = display.map(null, tree, cursor);
            Scroll(tree, cursor.x, cursor.y);
            display.timerExec(ScrollSpeed, Heartbeat);
          }
        };
    Listener listener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.MouseEnter:
                Tracking = true;
                display.timerExec(0, Heartbeat);
                break;
              case SWT.MouseExit:
                Tracking = false;
                break;
            }
          }
        };
    tree.addListener(SWT.MouseEnter, listener);
    tree.addListener(SWT.MouseExit, listener);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Пример #24
0
  public void createControl(Composite parent) {
    final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    Composite main = new Composite(parent, SWT.NONE);
    // use zero spacing to save some real estate here
    GridLayoutFactory.fillDefaults().spacing(0, 0).applyTo(main);

    final Button internalModeButton = new Button(main, SWT.CHECK);
    internalModeButton.setText(UIText.ExistingOrNewPage_InternalModeCheckbox);
    internalModeButton.setToolTipText(UIText.ExistingOrNewPage_CreationInWorkspaceWarningTooltip);
    internalModeButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            internalMode = internalModeButton.getSelection();
            updateControls();
          }
        });

    externalComposite = new Composite(main, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(externalComposite);
    externalComposite.setLayout(new GridLayout(3, false));

    new Label(externalComposite, SWT.NONE)
        .setText(UIText.ExistingOrNewPage_ExistingRepositoryLabel);
    final Combo existingRepoCombo = new Combo(externalComposite, SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(existingRepoCombo);
    final ComboViewer v = new ComboViewer(existingRepoCombo);
    v.setContentProvider(new RepoComboContentProvider());
    v.setLabelProvider(new RepoComboLabelProvider());
    v.setInput(new Object());
    // the default ViewerSorter seems to do the right thing
    // i.e. sort as String
    v.setSorter(new ViewerSorter());

    existingRepoCombo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            selectedRepository = null;
            IStructuredSelection sel = (IStructuredSelection) v.getSelection();
            setRepository((Repository) sel.getFirstElement());
            updateControls();
          }
        });

    Button createRepoWizard = new Button(externalComposite, SWT.PUSH);
    createRepoWizard.setText(UIText.ExistingOrNewPage_CreateRepositoryButton);
    createRepoWizard.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            NewRepositoryWizard wiz = new NewRepositoryWizard(true);
            if (new WizardDialog(getShell(), wiz).open() == Window.OK) {
              v.refresh();
              selectedRepository = wiz.getCreatedRepository();
              v.setSelection(new StructuredSelection(selectedRepository));
              updateControls();
            }
          }
        });

    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_WorkingDirectoryLabel);
    workDir = new Text(externalComposite, SWT.BORDER | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(workDir);
    GridDataFactory.fillDefaults().applyTo(workDir);
    // leave the space between the "Create" and "Browse" buttons empty (i.e.
    // do not fill to the right border
    new Label(externalComposite, SWT.NONE);

    new Label(externalComposite, SWT.NONE).setText(UIText.ExistingOrNewPage_RelativePathLabel);
    relPath = new Text(externalComposite, SWT.BORDER);
    relPath.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            updateControls();
          }
        });

    GridDataFactory.fillDefaults().grab(true, false).applyTo(relPath);
    browseRepository = new Button(externalComposite, SWT.PUSH);
    browseRepository.setEnabled(false);
    browseRepository.setText(UIText.ExistingOrNewPage_BrowseRepositoryButton);
    browseRepository.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            dlg.setFilterPath(selectedRepository.getWorkTree().getPath());
            String directory = dlg.open();
            if (directory != null) {
              setRelativePath(directory);
              updateControls();
            }
          }
        });

    Table projectMoveTable =
        new Table(externalComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK | SWT.BORDER);
    projectMoveViewer = new CheckboxTableViewer(projectMoveTable);
    GridDataFactory.fillDefaults().span(3, 1).grab(true, true).applyTo(projectMoveTable);

    TableColumn tc;
    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_ProjectNameColumnHeader);
    tc.setWidth(100);

    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_CurrentLocationColumnHeader);
    tc.setWidth(250);

    tc = new TableColumn(projectMoveTable, SWT.NONE);
    tc.setText(UIText.ExistingOrNewPage_NewLocationTargetHeader);
    tc.setWidth(350);

    projectMoveTable.setHeaderVisible(true);
    projectMoveViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectMoveViewer.setLabelProvider(moveProjectsLabelProvider);
    projectMoveViewer.setInput(myWizard.projects);
    projectMoveViewer.addCheckStateListener(
        new ICheckStateListener() {
          public void checkStateChanged(CheckStateChangedEvent event) {
            updateControls();
          }
        });
    TableItem[] children = projectMoveViewer.getTable().getItems();
    for (int i = 0; i < children.length; i++) {
      TableItem item = children[i];
      IProject data = (IProject) item.getData();
      RepositoryFinder repositoryFinder = new RepositoryFinder(data);
      repositoryFinder.setFindInChildren(false);
      try {
        Collection<RepositoryMapping> find = repositoryFinder.find(new NullProgressMonitor());
        if (find.size() != 1) item.setChecked(true);
      } catch (CoreException e1) {
        item.setText(2, e1.getMessage());
      }
    }

    parentRepoComposite = new Composite(main, SWT.NONE);
    parentRepoComposite.setLayout(new GridLayout(3, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parentRepoComposite);

    tree = new Tree(parentRepoComposite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
    viewer = new CheckboxTreeViewer(tree);
    tree.setHeaderVisible(true);
    tree.setLayout(new GridLayout());
    tree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(3, 1).create());
    viewer.addCheckStateListener(
        new ICheckStateListener() {

          public void checkStateChanged(CheckStateChangedEvent event) {
            if (event.getChecked()) {
              ProjectAndRepo checkable = (ProjectAndRepo) event.getElement();
              for (TreeItem ti : tree.getItems()) {
                if (ti.getItemCount() > 0
                    || ((ProjectAndRepo) ti.getData()).getRepo().equals("")) // $NON-NLS-1$
                ti.setChecked(false);
                for (TreeItem subTi : ti.getItems()) {
                  IProject project = ((ProjectAndRepo) subTi.getData()).getProject();
                  if (checkable.getProject() != null
                      && !subTi.getData().equals(checkable)
                      && checkable.getProject().equals(project)) subTi.setChecked(false);
                }
              }
            }
          }
        });
    TreeColumn c1 = new TreeColumn(tree, SWT.NONE);
    c1.setText(UIText.ExistingOrNewPage_HeaderProject);
    c1.setWidth(100);
    TreeColumn c2 = new TreeColumn(tree, SWT.NONE);
    c2.setText(UIText.ExistingOrNewPage_HeaderLocation);
    c2.setWidth(400);
    TreeColumn c3 = new TreeColumn(tree, SWT.NONE);
    c3.setText(UIText.ExistingOrNewPage_HeaderRepository);
    c3.setWidth(200);
    boolean allProjectsInExistingRepos = true;
    for (IProject project : myWizard.projects) {
      RepositoryFinder repositoryFinder = new RepositoryFinder(project);
      repositoryFinder.setFindInChildren(false);
      try {
        Collection<RepositoryMapping> mappings;
        mappings = repositoryFinder.find(new NullProgressMonitor());
        Iterator<RepositoryMapping> mi = mappings.iterator();
        RepositoryMapping m = mi.hasNext() ? mi.next() : null;
        if (m == null) {
          // no mapping found, enable repository creation
          TreeItem treeItem = new TreeItem(tree, SWT.NONE);
          updateProjectTreeItem(treeItem, project);
          treeItem.setText(1, project.getLocation().toOSString());
          treeItem.setText(2, ""); // $NON-NLS-1$
          treeItem.setData(new ProjectAndRepo(project, "")); // $NON-NLS-1$
          allProjectsInExistingRepos = false;
        } else if (!mi.hasNext()) {
          // exactly one mapping found
          TreeItem treeItem = new TreeItem(tree, SWT.NONE);
          updateProjectTreeItem(treeItem, project);
          treeItem.setText(1, project.getLocation().toOSString());
          fillTreeItemWithGitDirectory(m, treeItem, false);
          treeItem.setData(new ProjectAndRepo(project, m.getGitDirAbsolutePath().toOSString()));
          treeItem.setChecked(true);
        } else {
          TreeItem treeItem = new TreeItem(tree, SWT.NONE);
          updateProjectTreeItem(treeItem, project);
          treeItem.setText(1, project.getLocation().toOSString());
          treeItem.setData(new ProjectAndRepo(project, "")); // $NON-NLS-1$

          TreeItem treeItem2 = new TreeItem(treeItem, SWT.NONE);
          updateProjectTreeItem(treeItem2, project);
          fillTreeItemWithGitDirectory(m, treeItem2, true);
          treeItem2.setData(new ProjectAndRepo(project, m.getGitDirAbsolutePath().toOSString()));
          while (mi.hasNext()) { // fill in additional mappings
            m = mi.next();
            treeItem2 = new TreeItem(treeItem, SWT.NONE);
            updateProjectTreeItem(treeItem2, project);
            fillTreeItemWithGitDirectory(m, treeItem2, true);
            treeItem2.setData(
                new ProjectAndRepo(
                    m.getContainer().getProject(), m.getGitDirAbsolutePath().toOSString()));
          }
          treeItem.setExpanded(true);
          allProjectsInExistingRepos = false;
        }
      } catch (CoreException e) {
        TreeItem treeItem2 = new TreeItem(tree, SWT.BOLD | SWT.ITALIC);
        treeItem2.setText(e.getMessage());
      }
    }

    createRepo = new Button(parentRepoComposite, SWT.PUSH);
    createRepo.setLayoutData(GridDataFactory.fillDefaults().create());
    createRepo.setText(UIText.ExistingOrNewPage_CreateButton);
    createRepo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            File gitDir = new File(repositoryToCreate.getText(), Constants.DOT_GIT);
            try {
              Repository repository = FileRepositoryBuilder.create(gitDir);
              repository.create();
              for (IProject project : getProjects(false).keySet()) {
                // If we don't refresh the project directories right
                // now we won't later know that a .git directory
                // exists within it and we won't mark the .git
                // directory as a team-private member. Failure
                // to do so might allow someone to delete
                // the .git directory without us stopping them.
                // (Half lie, we should optimize so we do not
                // refresh when the .git is not within the project)
                //
                if (!gitDir.toString().contains("..")) // $NON-NLS-1$
                project.refreshLocal(IResource.DEPTH_ONE, new NullProgressMonitor());
              }
              util.addConfiguredRepository(gitDir);
            } catch (IOException e1) {
              String msg =
                  NLS.bind(
                      UIText.ExistingOrNewPage_ErrorFailedToCreateRepository, gitDir.toString());
              org.eclipse.egit.ui.Activator.handleError(msg, e1, true);
            } catch (CoreException e2) {
              String msg =
                  NLS.bind(UIText.ExistingOrNewPage_ErrorFailedToRefreshRepository, gitDir);
              org.eclipse.egit.ui.Activator.handleError(msg, e2, true);
            }
            for (TreeItem ti : tree.getSelection()) {
              IPath projectPath = new Path(ti.getText(1));
              IPath gitPath = new Path(gitDir.toString());
              IPath relative = gitPath.makeRelativeTo(projectPath);
              ti.setText(2, relative.toOSString());
              ((ProjectAndRepo) ti.getData()).repo = gitDir.toString();
              ti.setChecked(true);
            }
            updateControls();
          }
        });
    repositoryToCreate = new Text(parentRepoComposite, SWT.SINGLE | SWT.BORDER);
    repositoryToCreate.setLayoutData(
        GridDataFactory.fillDefaults().grab(true, false).span(1, 1).create());
    repositoryToCreate.addListener(
        SWT.Modify,
        new Listener() {
          public void handleEvent(Event e) {
            if (repositoryToCreate.getText().equals("")) { // $NON-NLS-1$
              createRepo.setEnabled(false);
              return;
            }
            IPath fromOSString = Path.fromOSString(repositoryToCreate.getText());
            createRepo.setEnabled(
                minumumPath.matchingFirstSegments(fromOSString) == fromOSString.segmentCount());
          }
        });
    dotGitSegment = new Label(parentRepoComposite, SWT.NONE);
    dotGitSegment.setEnabled(false);
    dotGitSegment.setText(File.separatorChar + Constants.DOT_GIT);
    dotGitSegment.setLayoutData(
        GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).create());

    tree.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            tree.select((TreeItem) e.item);
            updateControls();
          }
        });

    Dialog.applyDialogFont(main);
    setControl(main);

    if (allProjectsInExistingRepos) {
      internalMode = true;
      internalModeButton.setSelection(true);
      updateControls();
    }
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {
    display = parent.getDisplay();
    sashForm = new SashForm(parent, SWT.VERTICAL);
    FillLayout layout = new FillLayout();
    sashForm.setLayout(layout);
    GridData data = new GridData(GridData.FILL_BOTH);
    sashForm.setLayoutData(data);
    initializeDialogUnits(sashForm);

    Composite composite = new Composite(sashForm, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    composite.setLayout(gridLayout);

    treeViewer = createTreeViewer(composite);
    data = new GridData(GridData.FILL_BOTH);
    data.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT);
    data.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH);
    Tree tree = treeViewer.getTree();
    tree.setLayoutData(data);
    tree.setHeaderVisible(true);
    activateCopy(tree);
    TreeViewerColumn nameColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    nameColumn.getColumn().setText(ProvUIMessages.ProvUI_NameColumnTitle);
    nameColumn.getColumn().setWidth(400);
    nameColumn.getColumn().setMoveable(true);
    nameColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            String label = iu.getProperty(IInstallableUnit.PROP_NAME, null);
            if (label == null) label = iu.getId();
            return label;
          }

          public Image getImage(Object element) {
            if (element instanceof ProvElement) return ((ProvElement) element).getImage(element);
            if (ProvUI.getAdapter(element, IInstallableUnit.class) != null)
              return ProvUIImages.getImage(ProvUIImages.IMG_IU);
            return null;
          }

          public String getToolTipText(Object element) {
            if (element instanceof AvailableIUElement
                && ((AvailableIUElement) element).getImageOverlayId(null) == ProvUIImages.IMG_INFO)
              return ProvUIMessages.RemedyElementNotHighestVersion;
            return super.getToolTipText(element);
          }
        });
    TreeViewerColumn versionColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    versionColumn.getColumn().setText(ProvUIMessages.ProvUI_VersionColumnTitle);
    versionColumn.getColumn().setWidth(200);
    versionColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            if (element instanceof IIUElement) {
              if (((IIUElement) element).shouldShowVersion()) return iu.getVersion().toString();
              return ""; //$NON-NLS-1$
            }
            return iu.getVersion().toString();
          }
        });
    TreeViewerColumn idColumn = new TreeViewerColumn(treeViewer, SWT.LEFT);
    idColumn.getColumn().setText(ProvUIMessages.ProvUI_IdColumnTitle);
    idColumn.getColumn().setWidth(200);

    idColumn.setLabelProvider(
        new ColumnLabelProvider() {
          public String getText(Object element) {
            IInstallableUnit iu = ProvUI.getAdapter(element, IInstallableUnit.class);
            return iu.getId();
          }
        });

    // Filters and sorters before establishing content, so we don't refresh unnecessarily.
    IUComparator comparator = new IUComparator(IUComparator.IU_NAME);
    comparator.useColumnConfig(getColumnConfig());
    treeViewer.setComparator(comparator);
    treeViewer.setComparer(new ProvElementComparer());
    ColumnViewerToolTipSupport.enableFor(treeViewer);
    contentProvider = new ProvElementContentProvider();
    treeViewer.setContentProvider(contentProvider);
    //		labelProvider = new IUDetailsLabelProvider(null, getColumnConfig(), getShell());
    //		treeViewer.setLabelProvider(labelProvider);

    // Optional area to show the size
    createSizingInfo(composite);

    // The text area shows a description of the selected IU, or error detail if applicable.
    iuDetailsGroup =
        new IUDetailsGroup(
            sashForm,
            treeViewer,
            convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_WIDTH),
            true);

    setControl(sashForm);
    sashForm.setWeights(getSashWeights());
    Dialog.applyDialogFont(sashForm);

    // Controls for filtering/presentation/site selection
    Composite controlsComposite = new Composite(composite, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;
    gridLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    controlsComposite.setLayout(layout);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    controlsComposite.setLayoutData(gd);

    final Runnable runnable =
        new Runnable() {
          public void run() {
            treeViewer.addSelectionChangedListener(
                new ISelectionChangedListener() {
                  public void selectionChanged(SelectionChangedEvent event) {
                    setDetailText(resolvedOperation);
                  }
                });
            setDrilldownElements(input, resolvedOperation);
            treeViewer.setInput(input);
          }
        };

    if (resolvedOperation != null && !resolvedOperation.hasResolved()) {
      try {
        getContainer()
            .run(
                true,
                false,
                new IRunnableWithProgress() {
                  public void run(IProgressMonitor monitor) {
                    resolvedOperation.resolveModal(monitor);
                    display.asyncExec(runnable);
                  }
                });
      } catch (Exception e) {
        StatusManager.getManager()
            .handle(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, e.getMessage(), e));
      }
    } else {
      runnable.run();
    }
  }
  @Override
  public void createPartControl(Composite parent) {
    // TODO Auto-generated method stub

    FormToolkit toolkit = new FormToolkit(parent.getDisplay());

    Composite composite = toolkit.createComposite(parent, SWT.NONE);

    // composite.setBounds(10, 94, 64, 64);

    composite.setBounds(10, 94, 64, 64);
    FormData fd_composite = new FormData();
    fd_composite.bottom = new FormAttachment(100, -10);
    fd_composite.right = new FormAttachment(0, 751);
    fd_composite.left = new FormAttachment(0, 10);
    composite.setLayoutData(fd_composite);
    composite.setLayout(new TreeColumnLayout());

    treeViewer = new TreeViewer(composite, SWT.BORDER);
    Tree localFilesTree = treeViewer.getTree();
    localFilesTree.setHeaderVisible(true);
    localFilesTree.setLinesVisible(true);

    Label lblNewLabel =
        toolkit.createLabel(parent, "Files on local machine"); // new Label(this, SWT.NONE);
    fd_composite.top = new FormAttachment(0, 212);
    FormData fd_lblNewLabel = new FormData();
    fd_lblNewLabel.bottom = new FormAttachment(composite, -6);
    fd_lblNewLabel.left = new FormAttachment(0, 10);
    fd_lblNewLabel.right = new FormAttachment(0, 230);
    lblNewLabel.setLayoutData(fd_lblNewLabel);
    // lblNewLabel.setText("Files on local machine");

    Label lblNewLabel_1 = toolkit.createLabel(parent, ""); // new Label(this, SWT.NONE);
    FormData fd_lblNewLabel_1 = new FormData();
    fd_lblNewLabel_1.left = new FormAttachment(0, 426);
    lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);
    lblNewLabel_1.setText("Files added");

    ListViewer listViewer = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
    List addedFilesList = listViewer.getList();
    fd_lblNewLabel_1.bottom = new FormAttachment(addedFilesList, -6);
    FormData fd_addedFilesList = new FormData();
    fd_addedFilesList.bottom = new FormAttachment(composite, -6);
    fd_addedFilesList.left = new FormAttachment(0, 420);
    fd_addedFilesList.right = new FormAttachment(100, -73);
    fd_addedFilesList.top = new FormAttachment(0, 30);
    addedFilesList.setLayoutData(fd_addedFilesList);

    Composite composite_1 =
        toolkit.createComposite(parent, SWT.NONE); // new Composite(this, SWT.NONE);
    FormData fd_composite_1 = new FormData();
    fd_composite_1.top = new FormAttachment(addedFilesList, 0, SWT.TOP);
    fd_composite_1.left = new FormAttachment(composite, 0, SWT.LEFT);
    fd_composite_1.right = new FormAttachment(addedFilesList, -6);
    fd_composite_1.bottom = new FormAttachment(lblNewLabel, -4);
    composite_1.setLayoutData(fd_composite_1);

    Label lblRemoteHost = toolkit.createLabel(parent, ""); // new Label(composite_1, SWT.NONE);
    lblRemoteHost.setBounds(10, 14, 102, 14);
    lblRemoteHost.setText("Remote host:");

    Label lblUsername = new Label(composite_1, SWT.NONE);
    lblUsername.setText("Username:"******"Password:"******"Instructor Account:");
    lblInstructorAccount.setBounds(10, 98, 114, 14);

    assignmentCodeText = new Text(composite_1, SWT.BORDER);
    assignmentCodeText.setBounds(128, 126, 172, 19);

    Label lblAssignmentCode = new Label(composite_1, SWT.NONE);
    lblAssignmentCode.setText("Assignment code:");
    lblAssignmentCode.setBounds(10, 126, 102, 14);

    instructorAccountText = new Text(composite_1, SWT.BORDER);
    instructorAccountText.setBounds(128, 97, 172, 19);

    Button btnRun = new Button(composite_1, SWT.NONE);
    btnRun.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            usernameText.setText("Hello worlds");
          }
        });
    btnRun.setBounds(318, 10, 76, 46);
    btnRun.setText("Run");

    Label lblTryProjectConfiguration =
        toolkit.createLabel(parent, ""); // new Label(this, SWT.NONE);
    FormData fd_lblTryProjectConfiguration = new FormData();
    fd_lblTryProjectConfiguration.top = new FormAttachment(lblNewLabel_1, 0, SWT.TOP);
    fd_lblTryProjectConfiguration.left = new FormAttachment(0, 10);
    lblTryProjectConfiguration.setLayoutData(fd_lblTryProjectConfiguration);
    lblTryProjectConfiguration.setText("Try project configuration");
  }
Пример #27
0
  public void createPartControl(Composite parent) {
    statusline = getViewSite().getActionBars().getStatusLineManager();
    statusline.setMessage(
        Activator.getImageDescriptor("icons/info.png").createImage(),
        Messages.StatusLine_DropFilesHint);
    makeActions();

    ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL);
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);
    Composite content = new Composite(scrolledComposite, SWT.NONE);
    content.setLayout(new GridLayout(1, false));
    scrolledComposite.setContent(content);

    toolBarManager = new ToolBarManager();
    toolBarManager.add(encryptFilesAction);
    toolBarManager.add(newFolderAction);
    toolBarManager.add(new Separator("static"));
    toolBarManager.add(exportSelectionAction);
    toolBarManager.add(renameAction);
    toolBarManager.add(deleteSelectionAction);
    toolBarManager.add(new Separator("static"));
    toolBarManager.add(expandAllAction);
    toolBarManager.add(collapseAllAction);

    ToolBar toolbar = toolBarManager.createControl(content);
    toolbar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));

    // Create the tree viewer as a child of the composite parent
    treeViewer =
        new TreeViewer(
            content, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

    // Anpassungen für TreeTable
    tree = treeViewer.getTree();

    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    treeViewer.getControl().setLayoutData(gridData);

    treeViewer.setUseHashlookup(true);

    /** * Tree table specific code starts ** */
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);

    for (SteadyTableIdentifier identifier : SteadyTableIdentifier.values()) {
      new TreeColumn(tree, SWT.NONE).setText(Messages.getSteadyTableColumnTitle(identifier));
      tree.getColumn(identifier.ordinal()).setWidth(identifier.columnWidth);
    }

    /** * Tree table specific code ends ** */

    // layout the tree viewer below the text field
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    treeViewer.getControl().setLayoutData(gridData);

    treeViewer.setContentProvider(new SteadyTreeTableContentProvider());
    treeViewer.setLabelProvider(new SteadyTreeTableLabelProvider());

    root = getInitialInput();
    treeViewer.setInput(root);
    treeViewer.expandToLevel(1);

    // Drag-Part //////////////////////////////////////////////////////////
    DragSource source = new DragSource(tree, DND.DROP_COPY | DND.DROP_MOVE);
    source.setTransfer(new Transfer[] {TextTransfer.getInstance()});
    source.addDragListener(new TreeDragSourceListener(tree));

    // Drop-Part //////////////////////////////////////////////////////////
    DropTarget dropTarget = new DropTarget(tree, DND.DROP_COPY | DND.DROP_DEFAULT);
    dropTarget.setTransfer(new Transfer[] {TextTransfer.getInstance(), FileTransfer.getInstance()});
    dropTarget.addDropListener(new TreeDropTargetAdapter(treeViewer, root));

    addListeners();
    createContextMenu();
    createFiltersAndSorters();
  }
  public ContactTab(final Composite composite) {
    super(composite, 0);
    this.setLayout(new GridLayout(1, false));

    Composite containerHeaderSession = new Composite(this, SWT.NONE);
    containerHeaderSession.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    containerHeaderSession.setLayout(new GridLayout(2, false));
    final Combo comboSession = new Combo(containerHeaderSession, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboSession.add("分类1");
    comboSession.add("分类2");
    comboSession.add("分类3");
    comboSession.add("分类4");
    comboSession.select(0);
    final Label labelHeader1 = new Label(containerHeaderSession, SWT.NONE);
    labelHeader1.setText("共1人");

    tree =
        new Tree(
            this, /*SWT.CHECK | */
            SWT.VIRTUAL
                | SWT.MULTI
                | SWT.BORDER
                | SWT.FULL_SELECTION
                | SWT.H_SCROLL
                | SWT.V_SCROLL);
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    // tree.setRedraw(true);
    tree.setLayoutData(new GridData(GridData.FILL_BOTH));
    for (int i = 0; i < titles.length; i++) {
      TreeColumn column = new TreeColumn(tree, SWT.NONE);
      column.setText(titles[i]);
    }
    tree.addTreeListener(
        new TreeAdapter() {
          @Override
          public void treeCollapsed(TreeEvent e) {
            super.treeCollapsed(e);
            expand();
          }

          @Override
          public void treeExpanded(TreeEvent e) {
            super.treeExpanded(e);
            expand();
          }

          private void expand() {
            // System.out.println("expand...");
            isExpanding = true;
            Display.getDefault()
                .timerExec(
                    500,
                    new Runnable() {
                      public void run() {
                        isExpanding = false;
                        // System.out.println("isGroupClick: " + isGroupClick);
                      }
                    });
          }
        });
    tree.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent event) {
            super.mouseDown(event);
          }

          @Override
          public void mouseDoubleClick(MouseEvent event) {
            super.mouseDoubleClick(event);
            Point point = new Point(event.x, event.y);
            TreeItem item = tree.getItem(point);
            // System.out.println("Mouse double click: " + item);
            if (item != null && item.getData() != null && isExpanding == false) {
              ContactInfoDialog dialog =
                  new ContactInfoDialog(getParent().getShell(), ContactInfoComposite.TYPE_EDIT);
              ContactInfo info = (ContactInfo) item.getData();
              dialog.setData(info);
              if (dialog.open() == ContactInfoDialog.OK) {
                AppData.getInstance().getMainWin().refreshContactData(true);
              }
            }
          }
        });
    tree.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            if (event.detail == SWT.CHECK) {
              TreeItem item = (TreeItem) event.item;
              boolean checked = item.getChecked();
              UIUtil.checkItems(item, checked);
              UIUtil.checkPath(item.getParentItem(), checked, false);
            } else {
              TreeItem item = (TreeItem) event.item;
              ContactInfo info = null;
              if (item != null && item.getData() != null) {
                info = (ContactInfo) item.getData();
              }
              AppData.getInstance().getMainWin().showDetail(info);
            }
          }
        });

    setupPopupMenu();

    Composite containerHeaderEdit = new Composite(this, SWT.NONE);
    containerHeaderEdit.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    containerHeaderEdit.setLayout(new GridLayout(7, false));

    final Label labelCatalog = new Label(containerHeaderEdit, SWT.PUSH);
    labelCatalog.setText("小类:");
    final Combo comboCatalog = new Combo(containerHeaderEdit, SWT.DROP_DOWN | SWT.READ_ONLY);
    comboCatalog.add("小类1");
    comboCatalog.add("小类2");
    final Label labelSearch = new Label(containerHeaderEdit, SWT.PUSH);
    labelSearch.setText("联系人搜索:");
    final Text textSearch = new Text(containerHeaderEdit, SWT.BORDER);
    textSearch.setLayoutData(new GridData(150, SWT.DEFAULT));

    final Button buttonAdd = new Button(containerHeaderEdit, SWT.PUSH);
    buttonAdd.setText("新增...");
    buttonAdd.setLayoutData(new GridData(100, SWT.DEFAULT));
    buttonAdd.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            AppData.getInstance().getMainWin().addContact();
          }
        });
    final Button buttonImport = new Button(containerHeaderEdit, SWT.PUSH);
    buttonImport.setText("导入...");
    buttonImport.setLayoutData(new GridData(100, SWT.DEFAULT));
    final Button buttonExport = new Button(containerHeaderEdit, SWT.PUSH);
    buttonExport.setText("导出...");
    buttonExport.setLayoutData(new GridData(100, SWT.DEFAULT));

    if (!USE_PACK) {
      for (int i = 0; i < titles.length; i++) {
        if (i == 0) {
          tree.getColumn(i).setWidth(200);
        } else {
          tree.getColumn(i).setWidth(100);
        }
      }
    }
    if (USE_VIRTUAL) {
      tree.addListener(
          SWT.SetData,
          new Listener() {
            @Override
            public void handleEvent(Event event) {
              TreeItem item = (TreeItem) event.item;
              TreeItem parentItem = item.getParentItem();
              String text = null;
              if (parentItem == null) {
                ContactGroupInfo groupInfo = groupInfoList.get(tree.indexOf(item));
                text = groupInfo.getGroupName() + " (共" + groupInfo.getSize() + "人)";
                item.setText(text);
                item.setItemCount(groupInfo.getSize());
                item.setExpanded(true);
              } else {
                ContactGroupInfo groupInfo = groupInfoList.get(tree.indexOf(parentItem));
                ContactInfo info = results.get(groupInfo.getIndex(parentItem.indexOf(item)));
                fillItem(item, info);
              }
              if (USE_PACK) {
                packTable();
              }
            }
          });
    }
    reloadData(false);
  }
Пример #29
0
  /** Create contents of the dialog. */
  private void createContents() {
    shlBundler = new Shell(getParent(), getStyle());
    shlBundler.setSize(626, 447);
    shlBundler.setText("Bundler");
    shlBundler.setLayout(new FormLayout());

    listViewerFiles = new ListViewer(shlBundler, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    list = listViewerFiles.getList();
    FormData fd_list = new FormData();
    fd_list.left = new FormAttachment(0, 10);
    list.setLayoutData(fd_list);
    listViewerFiles.setContentProvider(
        new IStructuredContentProvider() {
          public Object[] getElements(Object inputElement) {
            Vector v = (Vector) inputElement;
            return v.toArray();
          }

          public void dispose() {}

          public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
        });
    listViewerFiles.setLabelProvider(
        new LabelProvider() {
          public Image getImage(Object element) {
            return null;
          }

          public String getText(Object element) {
            return ((File) element).getName();
          }
        });
    listViewerFiles.setSorter(
        new ViewerSorter() {
          public int compare(Viewer viewer, Object e1, Object e2) {
            return ((File) e1).getName().compareTo(((File) e2).getName());
          }
        });
    lblNewLabel_3 = new Label(shlBundler, SWT.NONE);
    fd_list.top = new FormAttachment(lblNewLabel_3, 6);
    fd_lblNewLabel = new FormData();
    fd_lblNewLabel.left = new FormAttachment(0, 10);
    lblNewLabel_3.setLayoutData(fd_lblNewLabel);
    lblNewLabel_3.setText("folder list :");

    composite_5 = new Composite(shlBundler, SWT.NONE);
    fd_list.bottom = new FormAttachment(composite_5, 0, SWT.BOTTOM);
    composite_5.setLayout(new TreeColumnLayout());
    FormData fd_composite_5 = new FormData();
    fd_composite_5.top = new FormAttachment(lblNewLabel_3, 6);
    fd_composite_5.right = new FormAttachment(100, -10);
    composite_5.setLayoutData(fd_composite_5);

    treeViewerCategories = new TreeViewer(composite_5, SWT.BORDER | SWT.MULTI);
    Tree treeCategories = treeViewerCategories.getTree();
    treeCategories.setHeaderVisible(true);
    treeCategories.setLinesVisible(true);
    treeViewerCategories.setContentProvider(new CategoriesContentProvider());
    treeViewerCategories.setLabelProvider(new SinfilesLabelProvider());
    treeViewerCategories.setSorter(
        new ViewerSorter() {
          public int compare(Viewer viewer, Object e1, Object e2) {
            int cat1 = category(e1);
            int cat2 = category(e2);
            if (cat1 != cat2) return cat1 - cat2;
            if ((e1 instanceof Category) && (e2 instanceof Category))
              return ((Category) e1).getName().compareTo(((Category) e2).getName());
            else return ((File) e1).getName().compareTo(((File) e2).getName());
          }
        });
    // Expand the tree
    treeViewerCategories.setAutoExpandLevel(2);
    // Provide the input to the ContentProvider
    treeViewerCategories.setInput(new CategoriesModel(meta));
    treeViewerCategories.refresh();

    Button btnCancel = new Button(shlBundler, SWT.NONE);
    fd_composite_5.bottom = new FormAttachment(btnCancel, -5);
    fd_composite_5.bottom = new FormAttachment(btnCancel, -5);
    btnCancel.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            result = new String("Cancel");
            shlBundler.dispose();
          }
        });
    FormData fd_btnCancel = new FormData();
    fd_btnCancel.right = new FormAttachment(100, -10);
    fd_btnCancel.bottom = new FormAttachment(100, -10);
    btnCancel.setLayoutData(fd_btnCancel);
    btnCancel.setText("Cancel");

    Button btnCreate = new Button(shlBundler, SWT.NONE);
    btnCreate.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (sourceFolder.getText().length() == 0) {
              showErrorMessageBox("You must point to a folder containing sin files");
              return;
            }
            if ((device.getText().length() == 0)
                || (version.getText().length() == 0)
                || (branding.getText().length() == 0)) {
              showErrorMessageBox("Device, Versio, Branding : all fields must be set");
              return;
            }
            File f =
                new File(
                    OS.getWorkDir()
                        + File.separator
                        + "firmwares"
                        + File.separator
                        + _variant
                        + "_"
                        + version.getText()
                        + "_"
                        + branding.getText()
                        + ".ftf");
            if (f.exists()) {
              showErrorMessageBox("This bundle name already exists");
              return;
            }
            Bundle b = new Bundle();
            b.setMeta(meta);
            b.setDevice(_variant);
            b.setVersion(version.getText());
            b.setBranding(branding.getText());
            b.setCmd25(btnNoFinalVerification.getSelection() ? "true" : "false");
            if (!b.hasLoader()) {
              String result = Devices.getIdFromVariant(_variant);
              DeviceEntry ent = new DeviceEntry(result);
              System.out.println(ent.getLoader());
              if (ent.hasUnlockedLoader()) {
                String res = WidgetTask.openLoaderSelect(shlBundler);
                if (res.equals("U")) b.setLoader(new File(ent.getLoaderUnlocked()));
                else if (res.equals("L")) b.setLoader(new File(ent.getLoader()));
                else {
                  showErrorMessageBox("This bundle must contain a loader");
                  return;
                }

              } else {
                b.setLoader(new File(ent.getLoader()));
              }
            }
            createFTFJob j = new createFTFJob("Create FTF");
            j.setBundle(b);
            j.schedule();
            shlBundler.dispose();
          }
        });
    FormData fd_btnCreate = new FormData();
    fd_btnCreate.bottom = new FormAttachment(btnCancel, 0, SWT.BOTTOM);
    fd_btnCreate.right = new FormAttachment(btnCancel, -6);
    btnCreate.setLayoutData(fd_btnCreate);
    btnCreate.setText("Create");

    btnNewButton_1 = new Button(shlBundler, SWT.NONE);
    fd_list.right = new FormAttachment(btnNewButton_1, -6);
    fd_composite_5.left = new FormAttachment(btnNewButton_1, 6);
    btnNewButton_1.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) listViewerFiles.getSelection();
            Iterator i = selection.iterator();
            while (i.hasNext()) {
              File f = (File) i.next();
              files.remove(f);
              try {
                meta.process(f.getName(), f.getAbsolutePath());
                model.refresh(meta);
                treeViewerCategories.setInput(model);
              } catch (Exception ex) {
                ex.printStackTrace();
              }
              treeViewerCategories.setAutoExpandLevel(2);
              treeViewerCategories.refresh();
              listViewerFiles.refresh();
            }
          }
        });
    fd_btnNewButton_1 = new FormData();
    fd_btnNewButton_1.left = new FormAttachment(0, 353);
    fd_btnNewButton_1.right = new FormAttachment(100, -224);
    btnNewButton_1.setLayoutData(fd_btnNewButton_1);
    btnNewButton_1.setText("->");

    Button btnNewButton_2 = new Button(shlBundler, SWT.NONE);
    fd_btnNewButton_1.bottom = new FormAttachment(100, -143);
    btnNewButton_2.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection =
                (IStructuredSelection) treeViewerCategories.getSelection();
            Iterator i = selection.iterator();
            while (i.hasNext()) {
              Object o = i.next();
              if (o instanceof Category) {
                Category c = (Category) o;
                Iterator<File> j = c.getSinfiles().iterator();
                while (j.hasNext()) {
                  File f = j.next();
                  files.add(f);
                  meta.remove(f.getName());
                  model.refresh(meta);
                  treeViewerCategories.setAutoExpandLevel(2);
                  treeViewerCategories.refresh();
                  listViewerFiles.refresh();
                }
              }
              if (o instanceof File) {
                String internal = ((File) o).getName();
                files.add(new File(meta.getPath(internal)));
                meta.remove(internal);
                model.refresh(meta);
                treeViewerCategories.setAutoExpandLevel(2);
                treeViewerCategories.refresh();
                listViewerFiles.refresh();
              }
            }
          }
        });
    FormData fd_btnNewButton_2 = new FormData();
    fd_btnNewButton_2.top = new FormAttachment(btnNewButton_1, 23);
    fd_btnNewButton_2.right = new FormAttachment(btnNewButton_1, 0, SWT.RIGHT);
    fd_btnNewButton_2.left = new FormAttachment(0, 353);
    btnNewButton_2.setLayoutData(fd_btnNewButton_2);
    btnNewButton_2.setText("<-");
    Composite composite = new Composite(shlBundler, SWT.NONE);
    composite.setLayout(new GridLayout(3, false));
    FormData fd_composite = new FormData();
    fd_composite.left = new FormAttachment(0, 10);
    fd_composite.right = new FormAttachment(100, -10);
    fd_composite.top = new FormAttachment(0, 10);
    composite.setLayoutData(fd_composite);

    lblSelectSourceFolder = new Label(composite, SWT.NONE);
    GridData gd_lblSelectSourceFolder = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_lblSelectSourceFolder.widthHint = 121;
    lblSelectSourceFolder.setLayoutData(gd_lblSelectSourceFolder);
    lblSelectSourceFolder.setText("Select source folder :");

    sourceFolder = new Text(composite, SWT.BORDER);
    sourceFolder.setEditable(false);
    GridData gd_sourceFolder = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_sourceFolder.widthHint = 428;
    sourceFolder.setLayoutData(gd_sourceFolder);

    btnNewButton = new Button(composite, SWT.NONE);
    btnNewButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    btnNewButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dlg = new DirectoryDialog(shlBundler);

            // Set the initial filter path according
            // to anything they've selected or typed in
            dlg.setFilterPath(sourceFolder.getText());

            // Change the title bar text
            dlg.setText("Directory chooser");

            // Customizable message displayed in the dialog
            dlg.setMessage("Select a directory");

            // Calling open() will open and run the dialog.
            // It will return the selected directory, or
            // null if user cancels
            String dir = dlg.open();
            if (dir != null) {
              // Set the text box to the new selection
              if (!sourceFolder.getText().equals(dir)) {
                sourceFolder.setText(dir);
                meta.clear();
                files = new Vector();
                File srcdir = new File(sourceFolder.getText());
                File[] chld = srcdir.listFiles();
                for (int i = 0; i < chld.length; i++) {
                  if (chld[i].getName().toUpperCase().endsWith("SIN")
                      || (chld[i].getName().toUpperCase().endsWith("TA")
                          && !chld[i].getName().toUpperCase().contains("SIMLOCK"))
                      || (chld[i].getName().toUpperCase().endsWith("XML")
                          && !chld[i].getName().toUpperCase().contains("UPDATE"))) {
                    files.add(chld[i]);
                  }
                }
                srcdir = new File(sourceFolder.getText() + File.separator + "boot");
                if (srcdir.exists()) {
                  chld = srcdir.listFiles();
                  for (int i = 0; i < chld.length; i++) {
                    if (chld[i].getName().toUpperCase().endsWith("XML")) {
                      files.add(chld[i]);
                    }
                  }
                }
                model.refresh(meta);
                treeViewerCategories.setInput(model);
                listViewerFiles.setInput(files);
              }
            }
          }
        });
    btnNewButton.setText("...");

    Composite composite_1 = new Composite(shlBundler, SWT.NONE);
    fd_lblNewLabel.top = new FormAttachment(0, 154);
    composite_1.setLayout(new GridLayout(3, false));
    FormData fd_composite_1 = new FormData();
    fd_composite_1.bottom = new FormAttachment(lblNewLabel_3, -6);
    fd_composite_1.right = new FormAttachment(composite_5, 0, SWT.RIGHT);
    fd_composite_1.top = new FormAttachment(composite, 2);
    fd_composite_1.left = new FormAttachment(0, 10);
    composite_1.setLayoutData(fd_composite_1);

    lblNewLabel = new Label(composite_1, SWT.NONE);
    GridData gd_lblNewLabel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gd_lblNewLabel.widthHint = 68;
    lblNewLabel.setLayoutData(gd_lblNewLabel);
    lblNewLabel.setText("Device :");

    device = new Text(composite_1, SWT.BORDER);
    device.setToolTipText("Double click to get list of devices");
    device.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDoubleClick(MouseEvent e) {
            String result = WidgetTask.openDeviceSelector(shlBundler);
            if (result.length() > 0) {
              DeviceEntry ent = new DeviceEntry(result);
              String variant = WidgetTask.openVariantSelector(ent.getId(), shlBundler);
              device.setText(ent.getName() + " (" + variant + ")");
              _variant = variant;
            }
          }
        });
    device.setEditable(false);
    GridData gd_device = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_device.widthHint = 355;
    device.setLayoutData(gd_device);
    new Label(composite_1, SWT.NONE);

    lblNewLabel_2 = new Label(composite_1, SWT.NONE);
    lblNewLabel_2.setText("Branding :");

    branding = new Text(composite_1, SWT.BORDER);
    GridData gd_branding = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_branding.widthHint = 355;
    branding.setLayoutData(gd_branding);

    btnNoFinalVerification = new Button(composite_1, SWT.CHECK);
    btnNoFinalVerification.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
    btnNoFinalVerification.setText("No final verification");

    Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
    lblNewLabel_1.setText("Version :");

    version = new Text(composite_1, SWT.BORDER);
    GridData gd_version = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_version.widthHint = 355;
    version.setLayoutData(gd_version);
    new Label(composite_1, SWT.NONE);
    Label lblFirmwareContent = new Label(shlBundler, SWT.NONE);
    fd_lblNewLabel.right = new FormAttachment(lblFirmwareContent, -67);
    FormData fd_lblFirmwareContent = new FormData();
    fd_lblFirmwareContent.right = new FormAttachment(composite_5, 0, SWT.RIGHT);
    fd_lblFirmwareContent.bottom = new FormAttachment(composite_5, -6);
    fd_lblFirmwareContent.left = new FormAttachment(composite_5, 0, SWT.LEFT);
    lblFirmwareContent.setLayoutData(fd_lblFirmwareContent);
    lblFirmwareContent.setText("Firmware content :");

    branding.setText(_branding);
    version.setText(_version);
    if (_deviceName.length() > 0) device.setText(_deviceName + " (" + _variant + ")");
  }