コード例 #1
0
  /**
   * Sets a CoWolf-Marker to give IResource.
   *
   * @param sourceRes used in the marker message to show the user which resource was changed.
   * @param targetRes on that the marker should be set.
   */
  private void setMarker(final IResource sourceRes, final IResource targetRes) {

    WorkspaceJob job =
        new WorkspaceJob("Set marker to invalid models") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            IMarker resMarker = targetRes.createMarker(COWOLF_PROBLEM);

            if (resMarker.exists()) {

              resMarker.setAttribute(
                  IMarker.MESSAGE,
                  "The associated source model ('"
                      + sourceRes.getName()
                      + "') was changed. It's recommended to perform a co-evolution.");
              resMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
              resMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
            }

            return Status.OK_STATUS;
          }
        };

    job.setRule(targetRes);
    job.schedule();
  }
コード例 #2
0
  public static void executeCreateModels(
      final EditorInputEMF alternative, final ModelType[] types) {

    WorkspaceJob job =
        new WorkspaceJob("Creating new models") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            monitor.beginTask("Creating new models", 2 * types.length + 1);

            ResourceSet modelResSet = new ResourceSetImpl();
            ResourceSet diagramResSet = new ResourceSetImpl();

            ModelUtils.createModels(
                modelResSet, diagramResSet, alternative.getResource(), types, monitor);
            for (Resource res : modelResSet.getResources()) {
              alternative.addSubResource(ExplorerProjectPaths.getFileFromEmfResource(res));
            }

            monitor.subTask("Saving alternative");
            alternative.save();
            monitor.worked(1);

            // IFile repFile = ExplorerProjectPaths.getNonexistingSubFile(alternative.getResource(),
            // "model", ModelType.REPRESENTATIONS.getFileExtension());
            // ResourceUtils.createSystemDiagramRepresentation((SystemImpl)alternative.getModelRootObject(ModelType.SYSTEM.getToolchainFileID()), repFile, modelResSet);

            return new Status(IStatus.OK, Activator.PLUGIN_ID, "Creating new models done.");
          }
        };

    job.setUser(true);
    job.schedule();
  }
コード例 #3
0
  public static void executeImportModels(
      final EditorInputEMF alternative, final Resource[] resources, final boolean copy) {

    WorkspaceJob job =
        new WorkspaceJob("Copying models into alternative") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            monitor.beginTask("Importing models into alternative", 6 * resources.length);

            if (copy) {
              ExplorerProjectPaths.copyEMFResources(alternative.getResource(), resources, monitor);
            }

            for (Resource resource : resources) {
              IFile f = ExplorerProjectPaths.getFileFromEmfResource(resource);
              alternative.addSubResource(f);
            }

            return new Status(IStatus.OK, Activator.PLUGIN_ID, "Copying models done.");
          }
        };

    job.setUser(true);
    job.schedule();
  }
コード例 #4
0
ファイル: TypingManager.java プロジェクト: csytang/Loong_de
  /** do not call from within a job */
  protected void reevaluateFileChecks(final Set<CLRAnnotatedSourceFile> files) {
    final HashSet<ITypingCheck> checks = new HashSet<ITypingCheck>(knownChecks);
    WorkspaceJob op =
        new WorkspaceJob("Reevaluate Typing") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            Map<IProject, Collection<CLRAnnotatedSourceFile>> groupedFiles = groupByProject(files);
            for (Entry<IProject, Collection<CLRAnnotatedSourceFile>> fileGroup :
                groupedFiles.entrySet()) {

              List<ITypingProvider> typingProviders =
                  TypingExtensionManager.getInstance().getTypingProviders(fileGroup.getKey());
              for (ITypingProvider typingProvider : typingProviders) {
                typingProvider.prepareReevaluation(fileGroup.getValue(), monitor);
              }
            }
            // TODO currently pretty inefficient. should store
            // association
            // of checks to projects or files more directly
            for (ITypingCheck check : checks) {
              if (files.contains(check.getFile()))
                evaluateChecks(
                    Collections.singleton(check),
                    check.getFile().getResource().getProject(),
                    monitor);
            }
            return Status.OK_STATUS;
          }
        };
    op.setUser(true);
    op.schedule();
  }
コード例 #5
0
ファイル: MyPart.java プロジェクト: johnsteele/e4.resources
  private IProject initializeWorkspace() {
    IEclipsePreferences node = new InstanceScope().getNode(ResourcesPlugin.PI_RESOURCES);
    node.putBoolean(ResourcesPlugin.PREF_AUTO_REFRESH, true);
    try {
      node.flush();
    } catch (BackingStoreException e) {
      e.printStackTrace();
    }

    WorkspaceJob job =
        new WorkspaceJob("init workspace") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            MyPart.this.project =
                TwitterContentUtil.getOrCreateTwitterDemoProject(workspace, monitor);
            return Status.OK_STATUS;
          }
        };

    job.setRule(workspace.getRoot());
    job.schedule();

    return TwitterContentUtil.getTwitterDemoProject(workspace);
  }
コード例 #6
0
ファイル: TypingManager.java プロジェクト: csytang/Loong_de
  /** do not call from within a job */
  protected void reevaluateProjectChecks(final IProject project) {
    final HashSet<ITypingCheck> checks = new HashSet<ITypingCheck>(knownChecks);
    WorkspaceJob op =
        new WorkspaceJob("Reevaluate Typing") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            List<ITypingProvider> typingProviders =
                TypingExtensionManager.getInstance().getTypingProviders(project);
            for (ITypingProvider typingProvider : typingProviders) {
              typingProvider.prepareReevaluationAll(monitor);
            }

            // TODO currently pretty inefficient. should store association
            // of checks to projects or files more directly
            LinkedList<ITypingCheck> toCheck = new LinkedList<ITypingCheck>();
            for (ITypingCheck check : checks) {
              if (check.getFile().getResource().getProject() == project) toCheck.add(check);
            }
            evaluateChecks(toCheck, project, monitor);

            return Status.OK_STATUS;
          }
        };
    op.setUser(true);
    op.schedule();
  }
コード例 #7
0
ファイル: RunTestCaseAction.java プロジェクト: nokia/RED
  public static void runTestCase(final IStructuredSelection selection, final Mode mode) {
    final WorkspaceJob job =
        new WorkspaceJob("Launching Robot Tests") {

          @Override
          public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {

            final Map<IResource, List<String>> resourcesMapping = new HashMap<>();

            final List<RobotCase> selectedTestCases =
                Selections.getElements(selection, RobotCase.class);
            for (final RobotCase robotCase : selectedTestCases) {
              final IResource suiteFile = robotCase.getSuiteFile().getFile();
              if (!resourcesMapping.containsKey(suiteFile)) {
                resourcesMapping.put(suiteFile, new ArrayList<String>());
              }
              resourcesMapping.get(suiteFile).add(robotCase.getName());
            }
            RobotLaunchConfiguration.createLaunchConfigurationForSelectedTestCases(resourcesMapping)
                .launch(mode.launchMgrName, monitor);

            return Status.OK_STATUS;
          }
        };
    job.setUser(false);
    job.schedule();
  }
コード例 #8
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.jface.wizard.Wizard#performFinish()
   */
  @Override
  public boolean performFinish() {
    if (mainPage.getContainerFullPath().append(mainPage.getFileName()).getFileExtension() == null) {
      mainPage.setFileName(
          mainPage.getFileName() + '.' + GlobalParser.SUPPORTED_TTCN3_EXTENSIONS[1]);
    }
    final IFile newModule = mainPage.createNewFile();
    if (newModule != null) {
      try {
        if (optionsPage.isExcludeFromBuildSelected()) {
          newModule.setPersistentProperty(
              new QualifiedName(
                  FileBuildPropertyData.QUALIFIER,
                  FileBuildPropertyData.EXCLUDE_FROM_BUILD_PROPERTY),
              TRUE);
        }

        ProjectFileHandler pfHandler = new ProjectFileHandler(newModule.getProject());
        pfHandler.saveProjectSettings();
        newModule.touch(new NullProgressMonitor());

        WorkspaceJob refreshJob =
            new WorkspaceJob("Refreshing built resources") {
              @Override
              public IStatus runInWorkspace(final IProgressMonitor monitor) {
                boolean proceedingOK = SymbolicLinkHandler.createSymlinks(newModule);
                if (proceedingOK) {
                  proceedingOK = TITANBuilder.removeExecutable(newModule.getProject());
                }
                if (proceedingOK) {
                  proceedingOK = TITANBuilder.removeMakefile(newModule.getProject());
                }
                if (proceedingOK) {
                  TITANBuilder.invokeBuild(newModule.getProject());
                }

                return Status.OK_STATUS;
              }
            };
        refreshJob.setPriority(Job.LONG);
        refreshJob.setUser(false);
        refreshJob.setSystem(true);
        refreshJob.setProperty(
            IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        refreshJob.schedule();

        selectAndRevealNewModule(newModule);
      } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
      }
    }
    return true;
  }
コード例 #9
0
  private void show() {
    final IServerInternal server =
        (IServerInternal)
            ((SimpleUserNode) viewer.getTreeSelection().getFirstElement()).getRealObject();
    final RelationDataLoader dataLoader = new RelationDataLoader();
    WorkspaceJob loadDataAndShowWizardJob =
        new WorkspaceJob("Loading relations from server '" + server.getName() + "'") {
          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            final List<RelationData> relationData = dataLoader.loadData(server, monitor);
            if (!dataLoader.isCanceled()) {
              Collections.sort(relationData);

              monitor.done();
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        public void run() {
                          if (relationData.size() > 0) {
                            LoadRelationsWizard loadRelationsWizard =
                                new LoadRelationsWizard(relationData);
                            loadRelationsWizard.init(
                                PlatformUI.getWorkbench(), viewer.getTreeSelection());

                            WizardDialog dialog =
                                new WizardDialog(
                                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                    loadRelationsWizard);
                            dialog.create();
                            dialog.open();
                          } else {
                            MessageDialog.openInformation(
                                Display.getDefault().getActiveShell(),
                                "Load relations",
                                "No relation was found in server '" + server.getName() + "'.");
                          }
                        }
                      });
              return Status.OK_STATUS;
            } else {
              return Status.CANCEL_STATUS;
            }
          }

          @Override
          protected void canceling() {
            dataLoader.setCanceled(true);
          }
        };

    loadDataAndShowWizardJob.setUser(true);
    loadDataAndShowWizardJob.schedule();
  }
コード例 #10
0
  /**
   * Deletes all CoWolf-Markers of given IResource.
   *
   * @param changedRes
   */
  private void deleteCoWolfMarkers(final IResource changedRes) {

    WorkspaceJob job =
        new WorkspaceJob("Delete CoWolf-Marker of the model") {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

            changedRes.deleteMarkers(COWOLF_PROBLEM, false, IResource.DEPTH_ZERO);

            return Status.OK_STATUS;
          }
        };

    job.setRule(changedRes);
    job.schedule();
  }
コード例 #11
0
ファイル: TypingManager.java プロジェクト: csytang/Loong_de
  /** do not call from within a job */
  public void recheckFiles(List<CLRAnnotatedSourceFile> files) {
    HashMap<IProject, List<CLRAnnotatedSourceFile>> orderedFiles =
        new HashMap<IProject, List<CLRAnnotatedSourceFile>>();
    for (CLRAnnotatedSourceFile file : files) {
      List<CLRAnnotatedSourceFile> projectFiles = orderedFiles.get(file.getResource().getProject());
      if (projectFiles == null) {
        projectFiles = new ArrayList<CLRAnnotatedSourceFile>();
        orderedFiles.put(file.getResource().getProject(), projectFiles);
      }
      projectFiles.add(file);
    }

    for (Entry<IProject, List<CLRAnnotatedSourceFile>> fileSet : orderedFiles.entrySet()) {
      WorkspaceJob op = new TypecheckFilesJob(fileSet.getKey(), fileSet.getValue(), this);
      op.setUser(true);
      op.schedule();
    }
  }
コード例 #12
0
  public static void updateProjectReferences(
      IIncludePathEntry[] newEntries,
      IIncludePathEntry[] oldEntries,
      final IProject project,
      SubProgressMonitor monitor) {
    try {
      boolean changedReferences = false;
      final IProjectDescription projectDescription = project.getDescription();
      List<IProject> referenced = new ArrayList<IProject>();
      List<String> referencedNames = new ArrayList<String>();
      IProject[] referencedProjects = projectDescription.getReferencedProjects();
      for (IProject refProject : referencedProjects) {
        referenced.add(refProject);
        referencedNames.add(refProject.getName());
      }

      for (IIncludePathEntry oldEntry : oldEntries) {
        if (oldEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = oldEntry.getPath().lastSegment();
          if (!containsProject(newEntries, projectName)) {
            if (((IncludePathEntry) oldEntry).createdReference) {
              int index = referencedNames.indexOf(projectName);
              if (index >= 0) {
                changedReferences = true;
                referencedNames.remove(index);
                referenced.remove(index);
              }
            }
          }
        }
      }

      for (IIncludePathEntry newEntry : newEntries) {
        if (newEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) {
          String projectName = newEntry.getPath().lastSegment();
          if (!containsProject(oldEntries, projectName)) {
            if (!referencedNames.contains(projectName)) {
              changedReferences = true;
              ((IncludePathEntry) newEntry).createdReference = true;
              referenced.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
              referencedNames.add(projectName);
            }
          }
        }
      }
      if (changedReferences) {
        IProject[] referenceProjects =
            (IProject[]) referenced.toArray(new IProject[referenced.size()]);
        projectDescription.setReferencedProjects(referenceProjects);
        WorkspaceJob job =
            new WorkspaceJob(CoreMessages.getString("IncludePathEntry_2")) // $NON-NLS-1$
            {
              public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                project.setDescription(projectDescription, monitor);
                return Status.OK_STATUS;
              }
            };
        job.setRule(project.getParent());
        job.schedule();
      }
    } catch (CoreException e) {
      PHPEplPlugin.logError(e);
    }
  }
コード例 #13
0
  /** Refreshes the list of addons */
  protected void refreshAddons() {
    if (cmbAddonServer_ == null || tableAddons_ == null) {
      return;
    }

    if (loading_) {
      GUIUtils.showInfoMessageBox("Please wait for the previous query to finish.");
      return;
    }

    if (cmbAddonServer_.getSelectionIndex() == -1) {
      return;
    }

    currentPort_ = ports_.get(cmbAddonServer_.getSelectionIndex());
    if (StringUtils.isNullOrEmpty(currentPort_)) {
      return;
    }

    loading_ = true;
    tableAddons_.setItemCount(0);
    tableAddons_.clearAll();

    if (!StringUtils.isNullOrEmpty(currentPort_)) {
      WorkspaceJob loadAddons =
          new WorkspaceJob("Retrieving list...") {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
              monitor.beginTask("Retrieving list...", 100);
              monitor.worked(10);

              String installName = Preferences.getDefaultInstallName();

              OutputStream stderr =
                  GUIUtils.createConsole("Wesnoth Addon Manager", null, false).newOutputStream();

              ExternalToolInvoker tool =
                  WMLTools.runWesnothAddonManager(
                      installName,
                      null,
                      currentPort_,
                      Arrays.asList("-w", "-l"), // list addons in raw
                      // mode
                      null,
                      new OutputStream[] {stderr});
              tool.waitForTool();

              /**
               * parse the contents columns = [[" 0 - type", "1 - name", "2 - title", "3 - author",
               * "4 - version", "uploads", "5 - downloads", "size", "timestamp", "translate"]]
               */
              final String[] lines = StringUtils.getLines(tool.getOutputContent());
              final List<String[]> addons = new ArrayList<String[]>();

              String[] tmpColumns = null;
              int index = -1;

              for (String line : lines) {
                index = -1;

                if (line.startsWith("\\ campaign")) {
                  if (tmpColumns != null) {
                    addons.add(tmpColumns);
                  }
                  tmpColumns = new String[6];
                } else if (line.startsWith("  \\ type")) {
                  index = 0;
                } else if (line.startsWith("  \\ name")) {
                  index = 1;
                } else if (line.startsWith("  \\ title")) {
                  index = 2;
                } else if (line.startsWith("  \\ author")) {
                  index = 3;
                } else if (line.startsWith("  \\ version")) {
                  index = 4;
                } else if (line.startsWith("  \\ downloads")) {
                  index = 5;
                }

                // got something interesting? parse it
                if (tmpColumns != null && index != -1) {
                  int firstIndex = line.indexOf('\'') + 1;
                  int lastIndex = line.lastIndexOf('\'');

                  if (lastIndex < firstIndex) {
                    lastIndex = line.length();
                  }

                  tmpColumns[index] = line.substring(firstIndex, lastIndex).trim();
                }
              }

              // need GUI Thread access
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          // skipp 1st line since it's just the header
                          for (String[] addon : addons) {

                            TableItem tableItem = new TableItem(tableAddons_, SWT.NONE);
                            tableItem.setText(
                                new String[] {
                                  addon[0], addon[1], addon[2], addon[3], addon[4], addon[5]
                                });
                          }

                          tableAddons_.forceFocus();
                        }
                      });
              loading_ = false;

              monitor.worked(100);
              monitor.done();
              return Status.OK_STATUS;
            }
          };
      loadAddons.schedule();
    }
  }
コード例 #14
0
  /** Downloads the currently selected addon */
  protected void downloadAddon() {
    if (tableAddons_.getSelectionIndex() == -1) {
      GUIUtils.showErrorMessageBox("No addon selected");
      return;
    }

    TableItem[] selection = tableAddons_.getSelection();
    final String addonName = selection[0].getText(1);

    WorkspaceJob downloadJob =
        new WorkspaceJob("Download") {

          @Override
          public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            monitor.beginTask("Downloading addon " + addonName, 100);

            String installName = Preferences.getDefaultInstallName();

            RunnableWithResult<String> runnable =
                new RunnableWithResult<String>() {
                  @Override
                  public void run() {
                    // ask the user to select the install for the project
                    SelectWesnothInstallDialog dialog = new SelectWesnothInstallDialog(null);
                    if (dialog.open() == SWT.OK) {
                      setResult(dialog.getSelectedInstallName());
                    }
                  }
                };

            Display.getDefault().syncExec(runnable);
            if (!StringUtils.isNullOrEmpty(runnable.getResult())) {
              installName = runnable.getResult();
            }

            final Paths paths = Preferences.getPaths(installName);

            OutputStream console =
                GUIUtils.createConsole("Wesnoth Addon Manager", null, false).newOutputStream();

            ExternalToolInvoker tool =
                WMLTools.runWesnothAddonManager(
                    installName,
                    null,
                    currentPort_,
                    Arrays.asList("-d", addonName, "-c", paths.getAddonsDir()),
                    new OutputStream[] {console},
                    new OutputStream[] {console});

            tool.waitForTool();

            monitor.worked(50);

            // ask user if he wants to create a project
            if (GUIUtils.showMessageBox(
                    "Do you want to create a new project for the downloaded addon?",
                    SWT.YES | SWT.NO)
                == SWT.YES) {

              ProjectUtils.createWesnothProject(
                  addonName, paths.getAddonsDir() + addonName, installName, monitor);
            }
            monitor.done();

            return Status.OK_STATUS;
          }
        };
    downloadJob.schedule();
  }
コード例 #15
0
ファイル: TypingManager.java プロジェクト: csytang/Loong_de
 /** do not call from within a job */
 public void recheckProjects(IProject[] projects) {
   WorkspaceJob op = new TypecheckProjectJob(projects, this);
   op.setUser(true);
   op.schedule();
 }