Ejemplo n.º 1
0
  @Override
  public void setSources(String... sources) {
    TreeItem[] items = tree.getSelection();
    if (items.length < 1) return;
    TreeItem item = items[0];
    if (lastSelectedItem == item) return;

    if (lastSelectedItem != null && !lastSelectedItem.isDisposed()) {
      lastSelectedItem.setBackground(new Color(getDisplay(), 255, 255, 255));
      lastSelectedItem.setExpanded(false);
      lastSelectedItem.removeAll();
    }
    lastSelectedItem = item;
    lastSelectedItem.setBackground(new Color(getDisplay(), 190, 190, 255));

    if (sources == null || sources.length < 1) return;

    for (String source : sources) {
      item = new TreeItem(lastSelectedItem, SWT.NONE);
      item.setFont(UIDATA.FONT_9);
      int idx = source.indexOf('.');
      if (idx > -1) source = source.substring(idx + 1);
      item.setText(source);
    }
    if (!lastSelectedItem.getExpanded()) lastSelectedItem.setExpanded(true);
  }
Ejemplo n.º 2
0
  // --------------------------------------------------------------------------------
  private void drawItem(String parentFieldName, TreeItem parentItem, List data, boolean expand) {
    for (int i = 0; i < data.size(); ++i) {
      TreeItem newItem = new TreeItem(parentItem, SWT.NONE);
      Object value = data.get(i);
      newItem.setText(1, getClassName(value));

      String fieldName = parentFieldName + "." + i;
      if (fieldName.startsWith(".")) {
        fieldName = fieldName.substring(1);
      }
      newItem.setData("fieldName", fieldName);
      newItem.setData("value", value);
      fieldNameTreeItemMap.put(fieldName, newItem);

      if (value instanceof Map) {
        newItem.setText("[" + i + "]");
        newItem.setImage(mapImage);
        drawItem(fieldName, newItem, (Map) value, expand);
      } else if (value instanceof List) {
        newItem.setText("[" + i + "]");
        newItem.setImage(listImage);
        drawItem(fieldName, newItem, (List) value, expand);
      } else {
        setItemInfo(newItem, "[" + i + "]", value);
      }

      if (expand) {
        parentItem.setExpanded(expand);
        newItem.setExpanded(expand);
      }
    }
  }
Ejemplo n.º 3
0
  /** Create contents of the dialog. */
  private void createContents() {
    this.shell = new Shell(this.getParent(), SWT.SHELL_TRIM | SWT.PRIMARY_MODAL);
    this.shell.setSize(300, 275);
    this.shell.setText("Columns");
    this.shell.setLayout(new FillLayout(SWT.HORIZONTAL));

    // ヘッダー
    String[] header = this.dialog.getTableHeader();
    // カラム設定を取得
    boolean[] visibles =
        AppConfig.get().getVisibleColumnMap().get(this.dialog.getClass().getName());
    if ((visibles == null) || (visibles.length != header.length)) {
      visibles = new boolean[header.length];
      Arrays.fill(visibles, true);
      AppConfig.get().getVisibleColumnMap().put(this.dialog.getClass().getName(), visibles);
    }

    Tree tree = new Tree(this.shell, SWT.BORDER | SWT.CHECK);

    for (int i = 1; i < header.length; i++) {
      TreeItem column = new TreeItem(tree, SWT.CHECK);
      column.setText(header[i]);
      column.setChecked(visibles[i]);
      column.setExpanded(true);
    }
    this.shell.addShellListener(new TreeShellAdapter(tree, visibles, this.dialog));
  }
Ejemplo n.º 4
0
 private void expandSelect() {
   if (fPathToSelect == null) return;
   if (fPathToSelect.isEmpty()) {
     fPathToSelect = null;
     fFileToSelect = null;
     return;
   }
   do {
     String name = fPathToSelect.getFirst();
     if (name.length() == 0) {
       fPathToSelect.removeFirst();
       continue;
     }
     FileInfo info = findFileInfo(fLastSelectedFileInfo, name);
     if (info == null) break;
     TreeItem item = findItem(info);
     if (item == null) break;
     fPathToSelect.removeFirst();
     if (fPathToSelect.isEmpty()) {
       fileTree.setSelection(item);
       fileTree.showItem(item);
     } else {
       item.setExpanded(true);
       fileTree.showItem(item);
     }
     fLastSelectedFileInfo = info;
   } while (!fPathToSelect.isEmpty());
 }
Ejemplo n.º 5
0
  private void reanalyzeStackFileInfo() {
    TreeItem item = getSelectedRootItemFromMainTree();
    if (item == null) {
      return;
    }

    StackFileInfo stackFileInfo = (StackFileInfo) item.getData();
    if (stackFileInfo == null) {
      return;
    }

    try {
      ParserConfigReader reader =
          new ParserConfigReader(stackFileInfo.getParserConfig().getConfigFilename());
      ParserConfig config = reader.read();

      StackParser.removeAllAnalyzedFile(stackFileInfo);

      processStackFile(stackFileInfo, config, null, false, true);
    } catch (RuntimeException ex) {
      closeStackFileInfo();
      throw ex;
    }
    item.removeAll();
    item.setText(stackFileInfo.toTreeInfo());
    addMainTreeSubItem(item, stackFileInfo.getStackAnalyzedInfoList());
    item.setExpanded(true);

    clearTable();
  }
Ejemplo n.º 6
0
 /**
  * Create a default TreeItem for a test class.
  *
  * @param parent
  * @param font
  * @return TreeItem for test class
  */
 private TreeItem createTestClassTreeItem(Tree parent, Font font) {
   TreeItem newClassNode = new TreeItem(parent, SWT.NONE);
   newClassNode.setFont(font);
   newClassNode.setExpanded(false);
   // Mark this test class as pass until we find a test method within it that says otherwise
   setColorAndIconForNode(newClassNode, ApexTestOutcome.Pass);
   return newClassNode;
 }
Ejemplo n.º 7
0
 private void expand(TreeItem item, boolean expand) {
   item.setExpanded(expand);
   TreeItem[] children = item.getItems();
   if (children == null) return;
   for (TreeItem child : children) {
     expand(child, expand);
   }
 }
Ejemplo n.º 8
0
 public void collapseNodes(TreeItem item) {
   item.setExpanded(false);
   TreeItem[] items = item.getItems();
   for (int i = 0; i < items.length; i++) {
     TreeItem child = items[i];
     collapseNodes(child);
   }
 }
Ejemplo n.º 9
0
  /**
   * Expand the TreeItems that did not pass.
   *
   * @param resultsTree
   */
  private void expandProblematicTestClasses(Tree resultsTree) {
    if (Utils.isEmpty(resultsTree)) return;

    for (TreeItem classNode : resultsTree.getItems()) {
      if (!classNode.getImage().equals(PASS_ICON)) {
        classNode.setExpanded(true);
      }
    }
  }
Ejemplo n.º 10
0
 private void addMainTree(StackFileInfo stackFileInfo) {
   Tree tree = getMainTree();
   TreeItem item = new TreeItem(tree, SWT.NONE);
   item.setText(stackFileInfo.toTreeInfo());
   item.setImage(Images.thread);
   item.setData(stackFileInfo);
   addMainTreeSubItem(item, stackFileInfo.getStackAnalyzedInfoList());
   item.setExpanded(true);
 }
Ejemplo n.º 11
0
 private void fillTableOld() {
   for (ContactInfo info : results) {
     appendRow(info);
   }
   if (parentItem != null) {
     parentItem.setExpanded(true);
     parentItem.setText(parentItem.getText() + " (共" + parentItemChildrenCount + "人)");
   }
   parentItem = null;
   parentItemChildrenCount = 0;
 }
Ejemplo n.º 12
0
  // --------------------------------------------------------------------------------
  private void drawItem(String parentFieldName, TreeItem parentItem, Map data, boolean expand) {
    Iterator p = data.keySet().iterator();
    while (p.hasNext()) {
      String key = (String) p.next();
      if (!data.containsKey(key)) {
        continue;
      }
      Object value = data.get(key);

      TreeItem newItem = new TreeItem(parentItem, SWT.NONE);
      newItem.setText(1, getClassName(value));

      String fieldName = parentFieldName + "." + key;
      if (fieldName.startsWith(".")) {
        fieldName = fieldName.substring(1);
      }
      newItem.setData("fieldName", fieldName);
      newItem.setData("value", value);
      fieldNameTreeItemMap.put(fieldName, newItem);

      if (value == null) {
        newItem.setText(key + " : null");
        newItem.setImage(nullImage);
      } else if (value instanceof Map) {
        newItem.setText(key);
        newItem.setImage(mapImage);
        drawItem(fieldName, newItem, (Map) value, expand);
      } else if (value instanceof List) {
        newItem.setText(key);
        newItem.setImage(listImage);
        drawItem(fieldName, newItem, (List) value, expand);
      } else {
        setItemInfo(newItem, key, value);
      }

      if (expand) {
        parentItem.setExpanded(expand);
        newItem.setExpanded(expand);
      }
    }
  }
 /**
  * Expands subtrees of given items. Items of type <code>PluginExtensionNode</code> that have
  * multiple children to expand will only be expanded to the that level. Further expanding is
  * required to reveal the whole subtree. This is for reasons of convenience.
  *
  * @param items tree items to be expand with their children
  */
 private void traverseChildrenAndSetExpanded(TreeItem[] items) {
   for (int i = 0; i < items.length; i++) {
     TreeItem treeItem = items[i];
     TreeItem[] children = treeItem.getItems();
     int extensionsChildCount = getExtensionsChildCount((IPluginParent) treeItem.getData());
     boolean furtherExpanding = !(extensionsChildCount > 1 && (!treeItem.getExpanded()));
     treeItem.setExpanded(furtherExpanding);
     if (furtherExpanding) {
       traverseChildrenAndSetExpanded(children);
     }
   }
 }
Ejemplo n.º 14
0
 public boolean getExpanded(Item item) {
   RepositoryNode repositoryNode = getRepositoryNode(item);
   if (repositoryNode != null && repositoryNode.getId() != null) {
     Boolean result = expanded.get(repositoryNode.getId());
     if (result != null) {
       if (item instanceof TreeItem) {
         TreeItem treeItem = (TreeItem) item;
         treeItem.setExpanded(result);
       }
     }
   }
   return true;
 }
  private boolean getData() {
    // Clear the tree top entry
    if (tiTree != null && !tiTree.isDisposed()) {
      tiTree.dispose();
    }

    tiTree = new TreeItem(wTree, SWT.NONE);
    tiTree.setImage(GUIResource.getInstance().getImageFolder());
    RepositoryDirectoryUI.getDirectoryTree(tiTree, dircolor, repositoryTree);
    tiTree.setExpanded(true);

    return true;
  }
Ejemplo n.º 16
0
  public void setSelectedCategory(String category) {
    if (category == null) return;
    if (lastSelectedItem != null && !lastSelectedItem.isDisposed()) {
      lastSelectedItem.setBackground(new Color(getDisplay(), 255, 255, 255));
      lastSelectedItem.setExpanded(false);
      lastSelectedItem.removeAll();
      lastSelectedItem = null;
    }

    TreeItem[] items = tree.getItems();
    if (items == null || items.length < 1) return;

    TreeItem selectedItem = null;
    for (TreeItem item : items) {
      if (item.getText().equals(category)) {
        selectedItem = item;
        break;
      }
    }
    if (selectedItem == null) return;
    tree.setSelection(selectedItem);
  }
Ejemplo n.º 17
0
 private void appendRow(ContactInfo info) {
   // System.out.println(str);
   final TreeItem item;
   String catalog = info.getCatalog();
   if (catalog == "" || catalog.length() == 0) {
     catalog = "未分组";
   }
   if (parentItem == null
       || parentItem.getText() == null
       || !parentItem.getText().equals(catalog)) {
     if (parentItem != null) {
       parentItem.setExpanded(true);
       parentItem.setText(parentItem.getText() + " (共" + parentItemChildrenCount + "人)");
     }
     parentItem = new TreeItem(tree, SWT.NONE);
     parentItem.setText(catalog);
     parentItemChildrenCount = 0;
   }
   item = new TreeItem(parentItem, SWT.NONE);
   parentItemChildrenCount++;
   fillItem(item, info);
 }
Ejemplo n.º 18
0
 private void expandDataNode(TreeItem item, boolean expand) {
   item.setExpanded(expand);
   TreeItem parent = item.getParentItem();
   if (parent == null || parent.isDisposed()) return;
   expandDataNode(parent, true);
 }
 private void createTreeItem(TreeItem parent, DirectoryEntry entry) {
   TreeItem item = new TreeItem(parent, SWT.NONE);
   fillTreeItem(item, entry);
   item.setExpanded(true);
 }
  public void display() throws Exception {
    /*
     * Create the display and shell.
     */
    display = new Display();
    final Shell shell = new Shell(display);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 3;
    shell.setLayout(layout);
    /*
     * Create a toolbar
     */
    {
      ToolBar toolbar = new ToolBar(shell, SWT.FLAT | SWT.RIGHT | SWT.NO_FOCUS);
      toolbar.setForeground(display.getSystemColor(SWT.COLOR_RED));
      toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
      ToolItem item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("File");
      item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("Edit");
      item = new ToolItem(toolbar, SWT.PUSH);
      item.setText("Help");
    }

    if (styleSheetStream == null) {
      // Create Styles themes
      createThemesStyleComposite(shell);
    }

    /*
     * Create a sash form.
     */
    SashForm form = new SashForm(shell, SWT.NONE);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));
    /*
     * Create the buddylist tree.
     */
    {
      tree = new Tree(form, SWT.SINGLE);
      tree.addSelectionListener(
          new SelectionListener() {
            public void widgetDefaultSelected(SelectionEvent e) {
              if (((TreeItem) e.item).getParentItem() != null) {
                try {
                  createChatControl(e.item);
                } catch (Exception ex) {
                  ex.printStackTrace();
                }
              }
            }

            public void widgetSelected(SelectionEvent e) {}
          });
      for (int i = 0; i < GROUPS.length; i++) {
        String g = GROUPS[i];
        TreeItem parentItem = new TreeItem(tree, SWT.NONE);
        parentItem.setText(g);
        for (int j = 0; j < NAMES.length; j++) {
          String n = NAMES[j];
          TreeItem item = new TreeItem(parentItem, SWT.NONE);
          item.setText(n);
        }
        parentItem.setExpanded(true);
      }
    }
    /*
     * Add the tabfolder
     */
    {
      tabFolder = new CTabFolder(form, SWT.CLOSE);
      tabFolder.setUnselectedCloseVisible(true);
      tabFolder.setUnselectedImageVisible(true);
      form.setWeights(new int[] {30, 70});
      // open a couple chats
      createChatControl(tree.getItem(0).getItems()[0]);
      createChatControl(tree.getItem(0).getItems()[1]);
      tabFolder.setSelection(tabFolder.getItem(0));
    }
    /*
     * Create a statusbar
     */
    {
      CLabel statusbar = new CLabel(shell, SWT.NONE);
      GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
      statusbar.setLayoutData(gd);
      statusbar.setText("Samantha Daryn is online");
    }
    /*
     * StyleHelper is used to parse and apply styles.
     */
    engine = getCSSEngine();
    if (styleSheetStream != null) {
      engine.parseStyleSheet(styleSheetStream);
      engine.applyStyles(shell, true);
    }
    /*
     * Now we open the shell.
     */
    shell.setSize(new Point(600, 600));
    shell.open();
    shell.setText("CSS Instant Messaging");
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Ejemplo n.º 21
0
 /**
  * Expand all items in the tree.
  *
  * @param items the items
  */
 private void expandAll(TreeItem[] items) {
   for (TreeItem ti : items) {
     ti.setExpanded(true);
     expandAll(ti.getItems());
   }
 }
Ejemplo n.º 22
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();
    }
  }
Ejemplo n.º 23
0
 /**
  * Flips the TreeItem from expanded to not expanded or vice-versa.
  *
  * @param ti The TreeItem to flip.
  */
 public static final void flipExpanded(TreeItem ti) {
   ti.setExpanded(!ti.getExpanded());
 }