/**
   * Method updateComponents.
   *
   * @param aParticipant - R4EParticipant
   */
  private void updateComponents(R4EParticipant aParticipant) {
    // Add item to the participants table
    final TableItem item = new TableItem(fAddedParticipantsTable, SWT.NONE);
    item.setText(0, aParticipant.getId());
    if (null != aParticipant.getEmail() && !("".equals(aParticipant.getEmail()))) {
      item.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
      item.setText(1, aParticipant.getEmail());
    } else {
      // Mark table item as not complete
      item.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
    }
    fAddedParticipantsTable.showItem(item);

    if (fParticipants.size() > 0) {
      fClearParticipantsButton.setEnabled(true);
      fRemoveUserButton.setEnabled(true);
      if (fUserToAddCombo instanceof CCombo) {
        ((CCombo) fUserToAddCombo).setText("");
      } else {
        ((Text) fUserToAddCombo).setText("");
      }
      getButton(IDialogConstants.OK_ID).setEnabled(true);
      getButton(IDialogConstants.OK_ID).setSelection(false);
    } else {
      if (fReviewSource) {
        getButton(IDialogConstants.OK_ID).setEnabled(false);
      }
    }
  }
  /**
   * Updates the visual of the given TableItem according to its IPathManager.
   *
   * @param item TableItem whose visual needs to be updated
   */
  private void updateTableItem(TableItem item) {

    AVRPathManager path = (AVRPathManager) item.getData();

    // add warn / error icons if path is empty / invalid
    boolean valid = path.isValid();
    boolean optional = path.isOptional();
    boolean empty = (path.getPath().isEmpty());

    if (valid && !empty) {
      // valid path
      item.setImage((Image) null);
    } else if ((valid && empty) || (!valid && optional)) {
      // valid but empty path or invalid and optional path (use for optional paths)
      item.setImage(
          PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    } else {
      // Path is invalid
      item.setImage(
          PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK));
    }

    item.setText(COLUMN_NAME, path.getName());
    item.setText(COLUMN_TYPE, path.getSourceType().toString());
    item.setText(COLUMN_PATH, path.getPath().toOSString());

    // Adjust color/font according to source type
    switch (path.getSourceType()) {
      case System:
        item.setFont(COLUMN_TYPE, fDialogFont);
        item.setFont(COLUMN_PATH, fDialogFont);
        item.setForeground(COLUMN_PATH, fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
        break;
      case Bundled:
        item.setFont(COLUMN_TYPE, fDialogFont);
        item.setFont(COLUMN_PATH, fDialogFont);
        item.setForeground(COLUMN_PATH, fTable.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
        break;
      case Custom:
        item.setFont(COLUMN_TYPE, fBoldFont);
        item.setFont(COLUMN_PATH, fBoldFont);
        item.setForeground(COLUMN_PATH, fTable.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    }

    // Updates the table layout.
    fTable.getColumn(COLUMN_NAME).pack();
    fTable.getColumn(COLUMN_TYPE).pack();
    fTable.getColumn(COLUMN_PATH).pack();
    fTable.layout();
  }
  /*
   * Handle the set data event. Set the item data of the requested item to the
   * corresponding proposal in the proposal cache.
   */
  private void handleSetData(Event event) {
    TableItem item = (TableItem) event.item;
    int index = proposalTable.indexOf(item);

    int proposalIndex = 0;
    for (String provider : proposalList.getProviderList()) {
      if (index == proposalIndex) {
        int count = proposalList.getCount(provider);
        String text = provider + " (" + count + " matching items)";
        item.setText(text);
        // Data == null => not selectable
        item.setData(null);

        Display display = Display.getCurrent();
        Color color = display.getSystemColor(SWT.COLOR_GRAY);
        FontData fontData = item.getFont().getFontData()[0];
        Font font =
            new Font(
                display,
                new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC | SWT.BOLD));
        item.setBackground(color);
        item.setFont(font);

        return;
      }
      proposalIndex++;
      for (IContentProposal proposal : proposalList.getProposals(provider)) {
        if (index == proposalIndex) {
          item.setText("  " + getString(proposal));
          item.setImage(getImage(proposal));
          item.setData(proposal);
          return;
        }
        proposalIndex++;
      }
    }
  }
Exemple #4
0
  /**
   * 建立Page外觀View
   *
   * @param composite
   */
  private void buildPage(Composite composite) {
    selectComposite = new Composite(composite, SWT.NONE);

    //		addLibBtn = new Button(composite, SWT.PUSH);
    //		addLibBtn.setText("Add Tag Library");
    //		addLibBtn.setLocation(getBoundsPoint(detAllBtn).x + 20, 10);
    //		addLibBtn.pack();
    //		addLibBtn.addSelectionListener(new SelectionAdapter() {
    //			@Override
    //			public void widgetSelected(SelectionEvent e) {
    //				ISelectionService selectionService =
    // Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
    //				ISelection selection = selectionService.getSelection();
    //				IProject project = null;
    //				if(selection instanceof IStructuredSelection) {
    //				    Object element = ((IStructuredSelection)selection).getFirstElement();
    //				    if (element instanceof IResource) {
    //				        project= ((IResource)element).getProject();
    //				    } else if (element instanceof PackageFragmentRootContainer) {
    //				        IJavaProject jProject = ((PackageFragmentRootContainer)element).getJavaProject();
    //				        project = jProject.getProject();
    //				    } else if (element instanceof IJavaElement) {
    //				        IJavaProject jProject= ((IJavaElement)element).getJavaProject();
    //				        project = jProject.getProject();
    //				    }
    //				} else if (selection instanceof ITextSelection) {
    //				    System.out.println("Fail");
    //				    return;
    //				}
    //				File lib = new File(project.getLocation().toFile().getPath() + "/lib");
    //				if(!lib.exists())
    //					lib.mkdir();
    //				File jar = new File(project.getLocation().toFile().getPath() + "/lib/Tag.jar");
    //				JarFileMaker jarFileMaker = new JarFileMaker();
    //				File test = new File("bin");
    //				jarFileMaker.createJarFile(jar, test, "ntut.csie.robusta.agile.exception");
    //			}
    //		});

    // 上半部,選擇要偵測的Smell群組
    smellTypeGroup = new Group(selectComposite, SWT.NONE);
    smellTypeGroup.setText(resource.getString("settingPage.smell.type"));
    smellTypeGroup.setLocation(10, 5);

    // 是否要選擇性偵測的Button
    checkbox_DetectAllSmells = new Button(smellTypeGroup, SWT.CHECK);
    checkbox_DetectAllSmells.setText(resource.getString("check.all.smell"));
    checkbox_DetectAllSmells.setLocation(10, 20);
    checkbox_DetectAllSmells.pack();
    checkbox_DetectAllSmells.setSelection(isDetectingAllSmells);
    checkbox_DetectAllSmells.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent e) {
            isDetectingAllSmells = !isDetectingAllSmells;
            setUserSetting();
          }
        });

    // 選擇EH Smell List
    smellList =
        new Table(
            smellTypeGroup,
            SWT.CHECK | SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.HIDE_SELECTION);
    smellList.setLocation(
        checkbox_DetectAllSmells.getBounds().x,
        checkbox_DetectAllSmells.getBounds().y + checkbox_DetectAllSmells.getBounds().height);
    smellList.setFont(new Font(composite.getDisplay(), "Arial", 11, SWT.NONE));
    smellList.setLinesVisible(true);
    smellList.setHeaderVisible(true);
    smellList.setItemCount(7);

    final TableColumn smellColumn = new TableColumn(smellList, SWT.NONE);
    String smellColumnDisplayText = resource.getString("settingPage.smell.type");
    smellColumn.setText(smellColumnDisplayText);
    smellColumn.setWidth(smellColumnDisplayText.length() * 9);
    // 自動調整bad smell Type Column的大小
    smellColumn.pack();
    final TableColumn descColumn = new TableColumn(smellList, SWT.NONE);
    descColumn.setText(resource.getString("settingPage.smell.description"));

    for (int i = 0; i < RLMarkerAttribute.CS_TOTAL_TYPE.length; i++) {
      TableItem item = smellList.getItem(i);
      item.setText(0, RLMarkerAttribute.CS_TOTAL_TYPE[i].replace('_', ' '));
      item.setFont(0, new Font(composite.getDisplay(), "Arial", 11, SWT.BOLD));
      item.setText(1, descText[i]);
    }
    // 自動調整bad smell Description Column的大小
    descColumn.pack();

    // 自動調整設定主頁面上半部視窗的大小
    smellList.pack();
    smellTypeGroup.pack();

    // Template Group
    templateCodeGroup = new Group(selectComposite, SWT.NONE);
    templateCodeGroup.setText(resource.getString("settingPage.codeExample"));
    templateCodeGroup.setLocation(10, getLowerRightCoordinate(smellTypeGroup).y + 5);

    // 是否要醒目標記程式碼
    checkbox_HighlightSmellCode = new Button(templateCodeGroup, SWT.CHECK);
    checkbox_HighlightSmellCode.setText(resource.getString("settingPage.codeExample.highlight"));
    checkbox_HighlightSmellCode.setLocation(10, 20);
    checkbox_HighlightSmellCode.pack();
    checkbox_HighlightSmellCode.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(final SelectionEvent e) {
            isShowWarning = checkbox_HighlightSmellCode.getSelection();

            int index = smellList.getSelectionIndex();
            if (index != -1) {
              changeTemplateText(index);
            }
          }
        });

    // Template Text
    templateCode = new StyledText(templateCodeGroup, SWT.BORDER | SWT.V_SCROLL);
    templateCode.setBounds(
        10, this.getLowerRightCoordinate(checkbox_HighlightSmellCode).y, 500, 170);
    templateCode.setText("");
    Font font = new Font(composite.getDisplay(), "Courier New", 14, SWT.NORMAL);
    templateCode.setFont(font);
    templateCodeGroup.pack();

    // 自動調整設定主頁面Container的大小
    selectComposite.pack();
    selectComposite.setSize(
        getLowerRightCoordinate(smellTypeGroup).x + 15, selectComposite.getBounds().height);
  }
  /*
   * Caches the specified proposals and repopulates the table if it has been
   * created.
   */
  private void setProposals(ContentProposalList newProposalList) {
    if (newProposalList == null || newProposalList.length() == 0) {
      newProposalList = getEmptyProposalArray();
    }
    this.proposalList = newProposalList;
    if (!isValid()) return;

    // If there is a table
    if (isValid()) {
      if (USE_VIRTUAL) {
        // Set and clear the virtual table. Data will be
        // provided in the SWT.SetData event handler.
        proposalTable.setItemCount(getTableLength());
        proposalTable.clearAll();
      } else {
        // Populate the table manually
        proposalTable.setRedraw(false);

        int itemCount = newProposalList.length() + newProposalList.getProviderList().size();
        proposalTable.setItemCount(itemCount);
        TableItem[] items = proposalTable.getItems();

        int index = 0;
        for (String provider : newProposalList.getProviderList()) {
          TableItem item = items[index];
          int count = newProposalList.getCount(provider);
          String text = provider + " (" + count + " matching items)";
          item.setText(text);
          // Data == null => not selectable
          item.setData(null);

          Display display = Display.getCurrent();
          Color color = display.getSystemColor(SWT.COLOR_GRAY);
          FontData fontData = item.getFont().getFontData()[0];
          Font font =
              new Font(
                  display,
                  new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC | SWT.BOLD));
          item.setBackground(color);
          item.setFont(font);

          index++;
          for (IContentProposal proposal : newProposalList.getProposals(provider)) {
            item.setText("  " + getString(proposal));
            item.setImage(getImage(proposal));
            item.setData(proposal);
            index++;
          }
        }

        proposalTable.setRedraw(true);
      }
      // Default to the first selection if there is content.
      if (newProposalList.length() > 0) {
        int index = 0;
        boolean selected = false;
        for (String provider : newProposalList.getProviderList()) {
          index++;
          if (!selected && newProposalList.getCount(provider) > 0) {
            selectProposal(index);
            selected = true;
          }
        }
      } else {
        // No selection, close the secondary popup if it was open
        if (infoPopup != null) {
          infoPopup.close();
        }
      }
    }
    footer.setText("");
  }