Ejemplo n.º 1
0
 @Override
 protected void okPressed() {
   List<TableIndex> tableIndexs = new ArrayList<TableIndex>();
   for (Object obj : treeViewer.getCheckedElements()) {
     tableIndexs.add((TableIndex) obj);
   }
   this.result = tableIndexs.toArray(new TableIndex[0]);
   super.okPressed();
 }
 @Override
 protected void okPressed() {
   List<TableColumn> columns = new ArrayList<TableColumn>();
   for (Object obj : treeViewer.getCheckedElements()) {
     columns.add((TableColumn) obj);
   }
   this.result = columns.toArray(new TableColumn[0]);
   super.okPressed();
 }
Ejemplo n.º 3
0
 /**
  * Gets all the user selected processes to be published.
  *
  * @return a list of <code>Process</code>
  */
 public List<Process> getSelectedProcesses() {
   List<Process> processes = new ArrayList<Process>();
   Object[] selected = processViewer.getCheckedElements();
   if (selected != null && selected.length > 0) {
     for (int i = 0; i < selected.length; i++) {
       if (selected[i] instanceof Process) {
         processes.add((Process) selected[i]);
       }
     }
   }
   return processes;
 }
 /** Validate the receiver and update the status with the result. */
 protected void updateOKStatus() {
   if (!fIsEmpty) {
     if (fValidator != null) {
       fCurrStatus = fValidator.validate(fViewer.getCheckedElements());
       updateStatus(fCurrStatus);
     } else if (!fCurrStatus.isOK()) {
       fCurrStatus =
           new Status(
               IStatus.OK,
               PlatformUI.PLUGIN_ID,
               IStatus.OK,
               "", //$NON-NLS-1$
               null);
     }
   } else {
     fCurrStatus =
         new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, fEmptyListMessage, null);
   }
   updateStatus(fCurrStatus);
 }
 /*
  * @see SelectionStatusDialog#computeResult()
  */
 protected void computeResult() {
   Object[] checked = fViewer.getCheckedElements();
   if (fExisting == null) {
     if (checked.length == 0) {
       checked = null;
     }
   } else {
     ArrayList res = new ArrayList();
     for (int i = 0; i < checked.length; i++) {
       Object elem = checked[i];
       if (!fExisting.contains(elem)) {
         res.add(elem);
       }
     }
     if (!res.isEmpty()) {
       checked = res.toArray();
     } else {
       checked = null;
     }
   }
   setSelectionResult(checked);
 }
Ejemplo n.º 6
0
  public void testGetCheckedElements() {
    CheckboxTreeViewer ctv = (CheckboxTreeViewer) fViewer;

    TestElement[] children = fRootElement.getChildren();

    List checked = new ArrayList((children.length + 1) / 2);

    for (int i = 0; i < children.length; i += 2) {
      ctv.setChecked(children[i], true);
      checked.add(children[i]);
    }

    Object[] actuallyChecked = ctv.getCheckedElements();

    for (int i = 0; i < actuallyChecked.length; i++) {
      assertTrue(
          "getCheckedElements should include all checked elements",
          checked.remove(actuallyChecked[i]));
    }

    assertTrue("getCheckedElements should not include any unchecked elements", checked.isEmpty());
  }
Ejemplo n.º 7
0
  /**
   * @param checked pass true to get the checked elements, false to get the selected elements
   * @return map between project and repository root directory (converted to an absolute path) for
   *     all projects selected by user
   */
  public Map<IProject, File> getProjects(boolean checked) {
    final Object[] elements;
    if (!internalMode)
      if (checked) elements = projectMoveViewer.getCheckedElements();
      else {
        ISelection selection = viewer.getSelection();
        elements = ((IStructuredSelection) selection).toArray();
      }
    else if (checked) elements = viewer.getCheckedElements();
    else {
      ISelection selection = viewer.getSelection();
      if (selection instanceof IStructuredSelection)
        elements = ((IStructuredSelection) selection).toArray();
      else elements = new Object[0];
    }

    Map<IProject, File> ret = new HashMap<IProject, File>(elements.length);
    for (Object ti : elements) {
      if (!internalMode) {
        File workdir = selectedRepository.getWorkTree();
        IProject project = (IProject) ti;
        IPath targetLocation = new Path(relPath.getText()).append(project.getName());
        File targetFile = new File(workdir, targetLocation.toOSString());
        ret.put(project, targetFile);

      } else {
        final IProject project = ((ProjectAndRepo) ti).getProject();
        String path = ((ProjectAndRepo) ti).getRepo();
        final IPath selectedRepo = Path.fromOSString(path);
        IPath localPathToRepo = selectedRepo;
        if (!selectedRepo.isAbsolute()) {
          localPathToRepo = project.getLocation().append(selectedRepo);
        }
        ret.put(project, localPathToRepo.toFile());
      }
    }
    return ret;
  }
  boolean createProjects() {
    saveInHistroy();

    final Object[] selectedCandidates = projectList.getCheckedElements();
    WorkspaceModifyOperation wop =
        new WorkspaceModifyOperation() {

          @Override
          protected void execute(IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            monitor.beginTask("", selectedCandidates.length);
            if (monitor.isCanceled()) {
              throw new OperationCanceledException();
            }
            try {
              for (int i = 0; i < selectedCandidates.length; i++) {
                ProjectCandidate pc = (ProjectCandidate) selectedCandidates[i];
                doCreateProject(pc, new SubProgressMonitor(monitor, 1));
              }
            } finally {
              monitor.done();
            }
          }
        };

    try {
      getContainer().run(true, true, wop);
    } catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return true;
  }
Ejemplo n.º 9
0
  protected void updateControls() {
    setMessage(null);
    setErrorMessage(null);
    if (!internalMode) {
      setDescription(UIText.ExistingOrNewPage_DescriptionExternalMode);
      if (this.selectedRepository != null) {
        workDir.setText(this.selectedRepository.getWorkTree().getPath());
        String relativePath = relPath.getText();
        File testFile = new File(this.selectedRepository.getWorkTree(), relativePath);
        if (!testFile.exists())
          setMessage(
              NLS.bind(UIText.ExistingOrNewPage_FolderWillBeCreatedMessage, relativePath),
              IMessageProvider.WARNING);
        IPath targetPath = new Path(selectedRepository.getWorkTree().getPath());
        targetPath = targetPath.append(relPath.getText());
        moveProjectsLabelProvider.targetFolder = targetPath;
        projectMoveViewer.refresh(true);
        browseRepository.setEnabled(true);
        for (Object checked : projectMoveViewer.getCheckedElements()) {
          IProject prj = (IProject) checked;
          IPath projectMoveTarget = targetPath.append(prj.getName());
          boolean mustMove = !prj.getLocation().equals(projectMoveTarget);
          File targetTest = new File(projectMoveTarget.toOSString());
          if (mustMove && targetTest.exists()) {
            setErrorMessage(
                NLS.bind(UIText.ExistingOrNewPage_ExistingTargetErrorMessage, prj.getName()));
            break;
          }
          File parent = targetTest.getParentFile();
          while (parent != null) {
            if (new File(parent, ".project").exists()) { // $NON-NLS-1$
              setErrorMessage(
                  NLS.bind(
                      UIText.ExistingOrNewPage_NestedProjectErrorMessage,
                      new String[] {prj.getName(), targetTest.getPath(), parent.getPath()}));
              break;
            }
            parent = parent.getParentFile();
          }
          // break after the first error
          if (getErrorMessage() != null) break;
        }
      } else workDir.setText(UIText.ExistingOrNewPage_NoRepositorySelectedMessage);
      setPageComplete(
          getErrorMessage() == null
              && selectedRepository != null
              && projectMoveViewer.getCheckedElements().length > 0);
    } else {
      setDescription(UIText.ExistingOrNewPage_description);
      IPath p = proposeNewRepositoryPath(tree.getSelection());
      minumumPath = p;
      if (p != null) {
        repositoryToCreate.setText(p.toOSString());
      } else {
        repositoryToCreate.setText(""); // $NON-NLS-1$
      }
      createRepo.setEnabled(p != null);
      repositoryToCreate.setEnabled(p != null);
      dotGitSegment.setEnabled(p != null);

      boolean pageComplete = viewer.getCheckedElements().length > 0;
      for (Object checkedElement : viewer.getCheckedElements()) {
        String path = ((ProjectAndRepo) checkedElement).getRepo();
        if (((ProjectAndRepo) checkedElement).getRepo() != null && path.equals("")) { // $NON-NLS-1$
          pageComplete = false;
        }
      }
      setPageComplete(pageComplete);
      // provide a warning if Repository is created in workspace
      for (IProject project : myWizard.projects) {
        if (createRepo.isEnabled()
            && ResourcesPlugin.getWorkspace()
                .getRoot()
                .getLocation()
                .isPrefixOf(project.getLocation())) {
          setMessage(
              UIText.ExistingOrNewPage_RepoCreationInWorkspaceCreationWarning,
              IMessageProvider.WARNING);
          break;
        }
      }
    }

    externalComposite.setVisible(!internalMode);
    parentRepoComposite.setVisible(internalMode);
    GridData gd;
    gd = (GridData) parentRepoComposite.getLayoutData();
    gd.exclude = !internalMode;

    gd = (GridData) externalComposite.getLayoutData();
    gd.exclude = internalMode;

    ((Composite) getControl()).layout(true);
  }
  /**
   * Validates the kernel composite input data.
   *
   * @return true if configured data is valid and can be retrieved.
   */
  public boolean isValid() {
    fIsTracepoints = fTracepointsActivateButton.getSelection();
    fIsSysCalls = fSysCallsActivateButton.getSelection();
    fIsDynamicProbe = fProbeActivateButton.getSelection();
    fIsDynamicFunctionProbe = fFunctionActivateButton.getSelection();

    // initialize tracepoint fields
    fIsAllTracepoints = false;
    fSelectedEvents = new ArrayList<>();

    if (fIsTracepoints) {
      Object[] checkedElements = fTracepointsViewer.getCheckedElements();
      for (int i = 0; i < checkedElements.length; i++) {
        ITraceControlComponent component = (ITraceControlComponent) checkedElements[i];
        if (component instanceof BaseEventComponent) {
          fSelectedEvents.add(component.getName());
        }
      }
      // verify if all events are selected
      int nbEvents = 0;
      List<ITraceControlComponent> comps =
          fProviderGroup.getChildren(KernelProviderComponent.class);
      for (ITraceControlComponent comp : comps) {
        nbEvents += comp.getChildren().length;
      }
      fIsAllTracepoints = (nbEvents == fSelectedEvents.size());
    }

    if (fIsDynamicProbe) {
      String temp = fProbeEventNameText.getText();
      if (temp.trim().isEmpty()
          || (!temp.matches("^[\\s]{0,}$")
              && !temp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { // $NON-NLS-1$ //$NON-NLS-2$
        MessageDialog.openError(
            getShell(),
            Messages.TraceControl_EnableEventsDialogTitle,
            Messages.TraceControl_InvalidProbeNameError
                + " ("
                + temp
                + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$

        return false;
      }

      fProbeEventName = temp;
      // fProbeString will be validated by lttng-tools
      fProbeString = fProbeText.getText();
    }

    // initialize function string
    fFunctionEventName = null;
    fFunctionString = null;
    if (fIsDynamicFunctionProbe) {
      String functionTemp = fFunctionEventNameText.getText();
      if (functionTemp.trim().isEmpty()
          || (!functionTemp.matches("^[\\s]{0,}$")
              && !functionTemp.matches("^[a-zA-Z0-9\\-\\_]{1,}$"))) { // $NON-NLS-1$ //$NON-NLS-2$
        MessageDialog.openError(
            getShell(),
            Messages.TraceControl_EnableEventsDialogTitle,
            Messages.TraceControl_InvalidProbeNameError
                + " ("
                + functionTemp
                + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$

        return false;
      }

      fFunctionEventName = functionTemp;
      // fFunctionString will be validated by lttng-tools
      fFunctionString = fFunctionText.getText();
    }

    // initialize filter with null
    fFilterExpression = null;
    if (fProviderGroup.isEventFilteringSupported(true)) {
      String tempFilter = fFilterText.getText();

      if (!tempFilter.trim().isEmpty()) {
        fFilterExpression = tempFilter;
      }
    }

    return true;
  }
 /*
  * @see SelectionStatusDialog#computeResult()
  */
 @Override
 protected void computeResult() {
   setResult(Arrays.asList(fViewer.getCheckedElements()));
 }