Search in sources :

Example 21 with IWorkingSet

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

the class GitCreateProjectViaWizardWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(mySelectionPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(myProjectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = myProjectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        myProjectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(monitor, currentProjects.length);
                        for (IProject current : currentProjects) {
                            if (!previousProjects.contains(current)) {
                                ConnectProviderOperation cpo = new ConnectProviderOperation(current, myRepository.getDirectory());
                                cpo.execute(progress.newChild(1));
                            } else {
                                progress.worked(1);
                            }
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = myCreateGeneralProjectPage.getProjectName();
                        defaultLocation[0] = myCreateGeneralProjectPage.isDefaultLocation();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            if (!defaultLocation[0]) {
                                desc.setLocation(new Path(myGitDir));
                            }
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                            File repoDir = myRepository.getDirectory();
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir);
                            cpo.execute(progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) File(java.io.File) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 22 with IWorkingSet

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

the class GitImportWizard method importProjects.

private void importProjects(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    switch(importWithDirectoriesPage.getWizardSelection()) {
        case GitSelectWizardPage.EXISTING_PROJECTS_WIZARD:
            {
                final Set<ProjectRecord> projectsToCreate = new HashSet<>();
                final List<IWorkingSet> workingSets = new ArrayList<>();
                // get the data from the pages in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectsToCreate.addAll(projectsImportPage.getCheckedProjects());
                        IWorkingSet[] workingSetArray = projectsImportPage.getSelectedWorkingSets();
                        workingSets.addAll(Arrays.asList(workingSetArray));
                        projectsImportPage.saveWidgetValues();
                    }
                });
                ProjectUtils.createProjects(projectsToCreate, workingSets.toArray(new IWorkingSet[workingSets.size()]), monitor);
                break;
            }
        case GitSelectWizardPage.NEW_WIZARD:
            {
                final File[] repoDir = new File[1];
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                final List<IProject> previousProjects = Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects());
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()).run();
                    }
                });
                IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor actMonitor) throws CoreException {
                        IProject[] currentProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                        SubMonitor progress = SubMonitor.convert(actMonitor, currentProjects.length);
                        for (IProject current : currentProjects) if (!previousProjects.contains(current)) {
                            ConnectProviderOperation cpo = new ConnectProviderOperation(current, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                        } else {
                            progress.worked(1);
                        }
                    }
                };
                try {
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
        case GitSelectWizardPage.GENERAL_WIZARD:
            {
                final String[] projectName = new String[1];
                final boolean[] defaultLocation = new boolean[1];
                final String[] path = new String[1];
                final File[] repoDir = new File[1];
                // get the data from the page in the UI thread
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        projectName[0] = createGeneralProjectPage.getProjectName();
                        defaultLocation[0] = createGeneralProjectPage.isDefaultLocation();
                        path[0] = importWithDirectoriesPage.getPath();
                        repoDir[0] = getTargetRepository().getDirectory();
                    }
                });
                try {
                    IWorkspaceRunnable wsr = new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor actMonitor) throws CoreException {
                            final IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(projectName[0]);
                            desc.setLocation(new Path(path[0]));
                            SubMonitor progress = SubMonitor.convert(actMonitor, 4);
                            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
                            prj.create(desc, progress.newChild(1));
                            prj.open(progress.newChild(1));
                            ConnectProviderOperation cpo = new ConnectProviderOperation(prj, repoDir[0]);
                            cpo.execute(progress.newChild(1));
                            ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_ONE, progress.newChild(1));
                        }
                    };
                    ResourcesPlugin.getWorkspace().run(wsr, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
                break;
            }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProjectDescription(org.eclipse.core.resources.IProjectDescription) NewProjectAction(org.eclipse.ui.actions.NewProjectAction) ArrayList(java.util.ArrayList) List(java.util.List) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 23 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project titan.EclipsePlug-ins by eclipse.

the class SearchPattern method create.

public static SearchPattern create(final IDialogSettings settings) {
    String loadedSearchString = settings.get("searchString");
    boolean loadedIsCaseSensitive = settings.getBoolean("isCaseSensitive");
    boolean loadedIsRegularExpression = settings.getBoolean("isRegularExpression");
    SortedMap<String, Boolean> loadedEvents = new TreeMap<String, Boolean>();
    for (String entry : Constants.EVENT_CATEGORIES.keySet()) {
        loadedEvents.put(entry, settings.getBoolean(entry));
    }
    Map<Field, Boolean> loadedLimitTo = new HashMap<Field, Boolean>();
    loadedLimitTo.put(Field.SOURCE_INFO, settings.getBoolean(Field.SOURCE_INFO.toString()));
    loadedLimitTo.put(Field.MESSAGE, settings.getBoolean(Field.MESSAGE.toString()));
    FilterPattern loadedFilterPattern = new FilterPattern(loadedSearchString, loadedLimitTo, loadedIsCaseSensitive, loadedIsRegularExpression);
    loadedFilterPattern.setEventsToFilter(loadedEvents, true, false);
    // $NON-NLS-1$
    String[] wsIds = settings.getArray("workingSets");
    IWorkingSet[] workingSets = null;
    if (wsIds != null && wsIds.length > 0) {
        IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
        workingSets = new IWorkingSet[wsIds.length];
        for (int i = 0; workingSets != null && i < wsIds.length; i++) {
            workingSets[i] = workingSetManager.getWorkingSet(wsIds[i]);
            if (workingSets[i] == null) {
                workingSets = null;
            }
        }
    }
    return new SearchPattern(loadedFilterPattern, settings.getInt("scope"), workingSets);
}
Also used : HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Field(org.eclipse.titan.log.viewer.models.FilterPattern.Field) FilterPattern(org.eclipse.titan.log.viewer.models.FilterPattern) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 24 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project titan.EclipsePlug-ins by eclipse.

the class LogSearchPage method collectFilesForSearch.

private List<IFile> collectFilesForSearch() {
    List<IFile> files = new ArrayList<IFile>();
    switch(getContainer().getSelectedScope()) {
        case ISearchPageContainer.WORKSPACE_SCOPE:
            IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
            for (IProject project : projects) {
                getLogFilesFromResource(project, files);
            }
            break;
        case ISearchPageContainer.SELECTION_SCOPE:
            IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
            ISelection selection = activePage.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                for (Iterator<?> it = structuredSelection.iterator(); it.hasNext(); ) {
                    Object o = it.next();
                    if (o instanceof IResource) {
                        getLogFilesFromResource((IResource) o, files);
                    }
                }
            }
            break;
        case ISearchPageContainer.SELECTED_PROJECTS_SCOPE:
            String[] projectNames = getContainer().getSelectedProjectNames();
            for (String name : projectNames) {
                IProject currentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
                getLogFilesFromResource(currentProject, files);
            }
            break;
        case ISearchPageContainer.WORKING_SET_SCOPE:
            IWorkingSet[] workingSets = getContainer().getSelectedWorkingSets();
            if (workingSets == null || workingSets.length < 1) {
                break;
            }
            for (IWorkingSet workingSet : workingSets) {
                for (IAdaptable element : workingSet.getElements()) {
                    getLogFilesFromResource((IResource) element, files);
                }
            }
            break;
        default:
            break;
    }
    return files;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IResource(org.eclipse.core.resources.IResource) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 25 with IWorkingSet

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

the class WorkspaceReleaseAction method selectionChanged.

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    projects = Collections.emptySet();
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        projects = new HashSet<IProject>();
        for (Iterator<?> itr = ss.iterator(); itr.hasNext(); ) {
            Object selected = itr.next();
            if (selected instanceof IProject) {
                projects.add((IProject) selected);
            } else if (selected instanceof IWorkingSet) {
                IWorkingSet workingSet = (IWorkingSet) selected;
                for (IAdaptable adaptable : workingSet.getElements()) {
                    IProject project = (IProject) adaptable.getAdapter(IProject.class);
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            } else if (selected instanceof IFile) {
                IFile bndFile = (IFile) selected;
                if (bndFile.getName().endsWith(Constants.DEFAULT_BND_EXTENSION)) {
                    if (!projects.contains(bndFile.getProject()))
                        projects.add(bndFile.getProject());
                }
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IProject(org.eclipse.core.resources.IProject) 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