Search in sources :

Example 46 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project mdw-designer by CenturyLinkCloud.

the class SearchPage method determineScope.

protected void determineScope() {
    if (searchPattern == null)
        searchPattern = "";
    if (scopedProjects == null) {
        // determine scoped projects from selection
        scopedProjects = new ArrayList<WorkflowProject>();
        if (searchPageContainer.getSelectedScope() == ISearchPageContainer.SELECTED_PROJECTS_SCOPE) {
            for (String projectName : searchPageContainer.getSelectedProjectNames()) {
                IProject project = MdwPlugin.getWorkspaceRoot().getProject(projectName);
                WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(project);
                if (workflowProject != null && !scopedProjects.contains(workflowProject))
                    scopedProjects.add(workflowProject);
            }
        } else if (searchPageContainer.getSelectedScope() == ISearchPageContainer.SELECTION_SCOPE) {
            if (searchPageContainer.getSelection() instanceof WorkflowProject)
                scopedProjects.add((WorkflowProject) searchPageContainer.getSelection());
            if (searchPageContainer.getSelection() instanceof WorkflowPackage)
                selectedPackage = (WorkflowPackage) searchPageContainer.getSelection();
        } else if (searchPageContainer.getSelectedScope() == ISearchPageContainer.WORKING_SET_SCOPE) {
            for (IWorkingSet workingSet : searchPageContainer.getSelectedWorkingSets()) {
                for (IAdaptable element : workingSet.getElements()) {
                    if (element instanceof IProject || element instanceof IJavaProject) {
                        IProject project = element instanceof IJavaProject ? ((IJavaProject) element).getProject() : (IProject) element;
                        WorkflowProject workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(project);
                        if (workflowProject != null && !scopedProjects.contains(workflowProject))
                            scopedProjects.add(workflowProject);
                    }
                }
            }
        } else {
            scopedProjects.addAll(WorkflowProjectManager.getInstance().getWorkflowProjects());
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) WorkflowPackage(com.centurylink.mdw.plugin.designer.model.WorkflowPackage) IJavaProject(org.eclipse.jdt.core.IJavaProject) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IProject(org.eclipse.core.resources.IProject) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 47 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project egit by eclipse.

the class LabelEventJob method decorateResourceMapping.

/**
 * Decorates a resource mapping (i.e. a Working Set).
 *
 * @param element the element for which the decoration was initially called
 * @param decoration the decoration
 * @throws CoreException
 */
private void decorateResourceMapping(Object element, IDecoration decoration) throws CoreException {
    @SuppressWarnings("restriction") ResourceMapping mapping = Utils.getResourceMapping(element);
    if (mapping == null) {
        return;
    }
    boolean isWorkingSet = mapping.getModelObject() instanceof IWorkingSet;
    IDecoratableResource decoRes;
    try {
        if (isWorkingSet) {
            decoRes = new DecoratableWorkingSet(mapping);
        } else {
            decoRes = new DecoratableResourceMapping(mapping);
        }
    } catch (IOException e) {
        throw new CoreException(Activator.createErrorStatus(NLS.bind(UIText.Decorator_exceptionMessage, element), e));
    }
    /*
		 *  don't render question marks on working sets. !isTracked() can have two reasons:
		 *   1) nothing is tracked.
		 *   2) no indexDiff for the contained projects ready yet.
		 *  in both cases, don't do anything to not pollute the display of the sets.
		 */
    if (!decoRes.isTracked() && isWorkingSet) {
        return;
    }
    helper.decorate(decoration, decoRes);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IOException(java.io.IOException) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 48 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project egit by eclipse.

the class AbstractGitCloneWizard method performClone.

/**
 * Do the clone using data which were collected on the pages
 * {@code validSource} and {@code cloneDestination}
 *
 * @param gitRepositoryInfo
 * @return if clone was successful
 * @throws URISyntaxException
 */
protected boolean performClone(GitRepositoryInfo gitRepositoryInfo) throws URISyntaxException {
    URIish uri = new URIish(gitRepositoryInfo.getCloneUri());
    UserPasswordCredentials credentials = gitRepositoryInfo.getCredentials();
    setWindowTitle(NLS.bind(UIText.GitCloneWizard_jobName, uri.toString()));
    final boolean allSelected;
    final Collection<Ref> selectedBranches;
    if (validSource.isSourceRepoEmpty()) {
        // fetch all branches of empty repo
        allSelected = true;
        selectedBranches = Collections.emptyList();
    } else {
        allSelected = validSource.isAllSelected();
        selectedBranches = validSource.getSelectedBranches();
    }
    final File workdir = cloneDestination.getDestinationFile();
    final Ref ref = cloneDestination.getInitialBranch();
    final String remoteName = cloneDestination.getRemote();
    boolean created = workdir.exists();
    if (!created)
        created = workdir.mkdirs();
    if (!created || !workdir.isDirectory()) {
        final String errorMessage = NLS.bind(UIText.GitCloneWizard_errorCannotCreate, workdir.getPath());
        ErrorDialog.openError(getShell(), getWindowTitle(), UIText.GitCloneWizard_failed, new Status(IStatus.ERROR, Activator.getPluginId(), 0, errorMessage, null));
        // let's give user a chance to fix this minor problem
        return false;
    }
    int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
    final CloneOperation op = new CloneOperation(uri, allSelected, selectedBranches, workdir, ref != null ? ref.getName() : null, remoteName, timeout);
    CredentialsProvider credentialsProvider = null;
    if (credentials != null) {
        credentialsProvider = new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword());
    } else {
        credentialsProvider = new EGitCredentialsProvider();
    }
    op.setCredentialsProvider(credentialsProvider);
    op.setCloneSubmodules(cloneDestination.isCloneSubmodules());
    rememberHttpHost(op, uri);
    configureFetchSpec(op, gitRepositoryInfo, remoteName);
    configurePush(op, gitRepositoryInfo, remoteName);
    configureRepositoryConfig(op, gitRepositoryInfo);
    configureGerrit(op, gitRepositoryInfo, credentialsProvider, remoteName, timeout);
    if (cloneDestination.isImportProjects()) {
        final IWorkingSet[] sets = cloneDestination.getWorkingSets();
        op.addPostCloneTask(new PostCloneTask() {

            @Override
            public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
                importProjects(repository, sets);
            }
        });
    }
    alreadyClonedInto = workdir.getPath();
    if (!callerRunsCloneOperation)
        runAsJob(uri, op, gitRepositoryInfo);
    else
        cloneOperation = op;
    return true;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) PostCloneTask(org.eclipse.egit.core.op.CloneOperation.PostCloneTask) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials) CloneOperation(org.eclipse.egit.core.op.CloneOperation) Ref(org.eclipse.jgit.lib.Ref) Repository(org.eclipse.jgit.lib.Repository) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 49 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project egit by eclipse.

the class SelectionPropertyTester method getRepositoryOfProjects.

/**
 * @param collection
 *            the selected elements
 * @param single
 *            <code>true</code> if only a single repository is allowed
 * @return the repository if any was found, <code>null</code> otherwise
 */
private static Repository getRepositoryOfProjects(Collection<?> collection, boolean single) {
    Repository repo = null;
    for (Object element : collection) {
        IContainer container = AdapterUtils.adapt(element, IProject.class);
        RepositoryMapping mapping = null;
        if (container != null) {
            mapping = RepositoryMapping.getMapping(container);
        } else {
            container = AdapterUtils.adapt(element, IContainer.class);
            if (container != null) {
                mapping = RepositoryMapping.getMapping(container);
            }
        }
        if (container != null && mapping != null && container.equals(mapping.getContainer())) {
            Repository r = mapping.getRepository();
            if (single && r != null && repo != null && r != repo) {
                return null;
            } else if (r != null) {
                repo = r;
            }
        } else {
            IWorkingSet workingSet = AdapterUtils.adapt(element, IWorkingSet.class);
            if (workingSet != null) {
                for (IAdaptable adaptable : workingSet.getElements()) {
                    Repository r = getRepositoryOfProject(adaptable);
                    if (single && r != null && repo != null && r != repo) {
                        return null;
                    } else if (r != null) {
                        repo = r;
                    }
                }
            }
        }
    }
    return repo;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IContainer(org.eclipse.core.resources.IContainer) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 50 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project bndtools by bndtools.

the class WorkingSetTracker method doWorkingSets.

static void doWorkingSets(final Project model, final IProject targetProject) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkingSetManager workingSetManager = workbench.getWorkingSetManager();
    String mergeProperties = model.mergeProperties("-workingset");
    if (mergeProperties == null)
        return;
    Parameters memberShips = new Parameters(mergeProperties);
    IWorkingSet[] allWorkingSets = workingSetManager.getAllWorkingSets();
    for (IWorkingSet currentWorkingSet : allWorkingSets) {
        Attrs attrs = memberShips.remove(currentWorkingSet.getName());
        boolean shouldBeMember = attrs != null && Processor.isTrue(attrs.get("member", "true"));
        IAdaptable[] elements = currentWorkingSet.getElements();
        List<IAdaptable> members = new ExtList<>(elements);
        boolean foundProjectInCurrentWorkingSet = false;
        for (Iterator<IAdaptable> it = members.iterator(); it.hasNext(); ) {
            IAdaptable member = it.next();
            if (member.getAdapter(IProject.class) == targetProject) {
                foundProjectInCurrentWorkingSet = true;
                if (!shouldBeMember) {
                    it.remove();
                }
            }
        }
        if (!foundProjectInCurrentWorkingSet && shouldBeMember) {
            members.add(targetProject);
        }
        if (elements.length != members.size()) {
            updateWorkingSet(currentWorkingSet, members);
        }
    }
    for (final Entry<String, Attrs> e : memberShips.entrySet()) {
        String name = e.getKey();
        boolean isMember = Processor.isTrue(e.getValue().get("member", "true"));
        if (!isMember)
            continue;
        if (!JAVAID_P.matcher(name).matches()) {
            SetLocation error = model.warning("Invalid working set name '%s'. Must use pattern of Java identifier", name);
            error.file(model.getPropertiesFile().getAbsolutePath());
            error.header("-workingset");
            continue;
        }
        IAdaptable[] members = new IAdaptable[1];
        members[0] = targetProject;
        IWorkingSet newWorkingSet = workingSetManager.createWorkingSet(name, members);
        newWorkingSet.setId("org.eclipse.jdt.ui.JavaWorkingSetPage");
        newWorkingSet.setLabel(null);
        workingSetManager.addWorkingSet(newWorkingSet);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) Parameters(aQute.bnd.header.Parameters) ExtList(aQute.lib.collections.ExtList) Attrs(aQute.bnd.header.Attrs) IProject(org.eclipse.core.resources.IProject) IWorkbench(org.eclipse.ui.IWorkbench) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) SetLocation(aQute.service.reporter.Reporter.SetLocation) IWorkingSet(org.eclipse.ui.IWorkingSet)

Aggregations

IWorkingSet (org.eclipse.ui.IWorkingSet)54 IWorkingSetManager (org.eclipse.ui.IWorkingSetManager)17 IAdaptable (org.eclipse.core.runtime.IAdaptable)15 IResource (org.eclipse.core.resources.IResource)10 IProject (org.eclipse.core.resources.IProject)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IWorkingSetSelectionDialog (org.eclipse.ui.dialogs.IWorkingSetSelectionDialog)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IWorkbench (org.eclipse.ui.IWorkbench)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Set (java.util.Set)2 IProjectDescription (org.eclipse.core.resources.IProjectDescription)2