private GradleImportOperation createImportOperation(IProgressMonitor m)
     throws FastOperationFailedException, OperationCanceledException, CoreException {
   m.beginTask("Create re-import operation", 1);
   try {
     GradleRefreshPreferences prefs =
         gradleProjects.iterator().next().getRootProject().getRefreshPreferences();
     List<HierarchicalEclipseProject> projects =
         new ArrayList<HierarchicalEclipseProject>(gradleProjects.size());
     Set<HierarchicalEclipseProject> relatedProjectsSet =
         new HashSet<HierarchicalEclipseProject>();
     for (GradleProject gradleProject : gradleProjects) {
       projects.add(gradleProject.getGradleModel(m));
       relatedProjectsSet.addAll(gradleProject.getAllProjectsInBuild());
     }
     GradleImportOperation op =
         new GradleImportOperation(
             projects,
             false,
             GradleImportOperation.createProjectMapping(
                 prefs.getUseHierarchicalNames(),
                 Arrays.asList(
                     relatedProjectsSet.toArray(
                         new HierarchicalEclipseProject[relatedProjectsSet.size()]))));
     op.setQuickWorkingSet(null); // this option only meaningfull on initial import.
     op.setReimport(true);
     op.verify();
     return op;
   } finally {
     m.done();
   }
 }
 /**
  * @return THe set of tasks that is valid. May return null if it is not possible at the moment to
  *     determine task validity (typically, this happens if we don;t have a Gradle project model
  *     ready yet. Callers should be ready to deal with that situation.
  */
 private Set<String> getValidTasks() {
   try {
     GradleProject gp = getTreeInput();
     if (gp != null) {
       return gp.getAllTasks();
     }
   } catch (FastOperationFailedException e) {
     // Ignore: may happen if gradle model not ready
   } catch (CoreException e) {
     GradleCore.log(e);
   }
   return null; // Couldn't determine what is valid
 }
  private void createProjectCombo(Composite _parent) {
    GridDataFactory grabHor = GridDataFactory.fillDefaults().grab(true, false);
    Composite parent = new Composite(_parent, SWT.NONE);
    parent.setLayout(new GridLayout(3, false));

    grabHor.applyTo(parent);

    Label label = new Label(parent, SWT.NONE);
    label.setText("Project");

    projectCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    List<GradleProject> projects = getGradleProjects();
    String[] items = new String[projects.size()];
    int i = 0;
    for (GradleProject p : projects) {
      items[i++] = p.getName();
    }
    projectCombo.setItems(items);

    if (project != null) {
      projectCombo.setText(project.getName());
    }

    projectCombo.addModifyListener(
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            projectComboChanged();
          }
        });

    refreshButton = new Button(parent, SWT.PUSH);
    refreshButton.setText("Refresh");
    refreshButton.setToolTipText("Rebuild the gradle model and refresh the task list");
    refreshButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent evt) {
            try {
              GradleProject currentProject = project;
              if (currentProject != null) {
                currentProject.requestGradleModelRefresh();
                taskSelectionTreeViewer.refresh();
              }
            } catch (CoreException e) {
              GradleCore.log(e);
            }
          }
        });

    grabHor.align(SWT.RIGHT, SWT.CENTER).applyTo(refreshButton);
  }
 private boolean haveGradleModel() {
   try {
     return project != null && project.getGradleModel() != null;
   } catch (FastOperationFailedException e) {
   } catch (CoreException e) {
     GradleCore.log(e);
   }
   return false;
 }
  private void setProject(GradleProject project) {
    // TODO: when restoring from persistent conf, can get non-existent projects...
    //  how to handle that case?
    if (this.project == project) // Don't do anything if project is unchanged
    return;

    //		if (this.project!=null) {
    //			this.project.removeModelListener(modelListener);
    //		}
    this.project = project;
    setChecked(Arrays.asList(new String[0]));
    //		if (this.project!=null) {
    //			this.project.addModelListener(modelListener);
    //		}
    setTreeInput(project);
    if (projectCombo != null) {
      if (project != null) {
        projectCombo.setText(project.getName());
      } else {
        projectCombo.deselectAll();
      }
    }
    updateLaunchConfigurationDialog();
  }