Search in sources :

Example 41 with IWorkingSet

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

the class ManualAssociationAwareWorkingSetManager method deleteEclipseResourcesWorkingSets.

/**
 * Deletes all Eclipse based working sets that belong to the 'Resources' working set type.
 */
private void deleteEclipseResourcesWorkingSets() {
    // Discard the Eclipse based working set manager state by deleting all 'Resources' working sets.
    final Iterator<IWorkingSet> itr = getAllEclipseResourceWorkingSetsIterator();
    final IWorkingSetManager manager = getWorkbench().getWorkingSetManager();
    while (itr.hasNext()) {
        final IWorkingSet next = itr.next();
        manager.removeWorkingSet(next);
    }
}
Also used : IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 42 with IWorkingSet

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

the class ManualAssociationAwareWorkingSetManager method getAllEclipseResourceWorkingSetsIterator.

/**
 * Returns with an iterator of all existing Eclipse based {@link IWorkingSet working sets} that belong to the
 * 'Resources' type. Includes all visible and hidden working sets.
 *
 * @return an iterator to all Eclipse based working sets form the 'Resources' type.
 */
private Iterator<IWorkingSet> getAllEclipseResourceWorkingSetsIterator() {
    final IWorkingSetManager manager = getWorkbench().getWorkingSetManager();
    final Iterable<IWorkingSet> allWorkingSets = asList(manager.getAllWorkingSets());
    return from(allWorkingSets).filter(RESOURCE_WORKING_SETS).iterator();
}
Also used : IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 43 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project liferay-ide by liferay.

the class BaseProjectWizard method addToWorkingSets.

protected void addToWorkingSets(IProject newProject) throws Exception {
    if (newProject != null) {
        List<WizardPagePart> wizardPages = part().getPages();
        WizardPagePart wizardPagePart = wizardPages.get(0);
        for (final FormComponentPart formPart : wizardPagePart.children().all()) {
            if (formPart instanceof WorkingSetCustomPart) {
                final WorkingSetCustomPart workingSetPart = (WorkingSetCustomPart) formPart;
                final IWorkingSet[] workingSets = workingSetPart.getWorkingSets();
                if (ListUtil.isNotEmpty(workingSets)) {
                    IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
                    workingSetManager.addToWorkingSets(newProject, workingSets);
                }
            }
        }
    }
}
Also used : FormComponentPart(org.eclipse.sapphire.ui.forms.FormComponentPart) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) WorkingSetCustomPart(com.liferay.ide.project.ui.wizard.WorkingSetCustomPart) WizardPagePart(org.eclipse.sapphire.ui.forms.WizardPagePart) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 44 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project liferay-ide by liferay.

the class WorkingSets method getWorkingSets.

public static String[] getWorkingSets() {
    List<String> workingSets = new ArrayList<>();
    IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
    for (IWorkingSet workingSet : workingSetManager.getWorkingSets()) {
        if (workingSet.isVisible()) {
            workingSets.add(workingSet.getName());
        }
    }
    return workingSets.toArray(new String[workingSets.size()]);
}
Also used : ArrayList(java.util.ArrayList) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSet(org.eclipse.ui.IWorkingSet)

Example 45 with IWorkingSet

use of org.eclipse.ui.IWorkingSet in project liferay-ide by liferay.

the class WorkingSetGroup method _createControl.

private void _createControl(Composite container) {
    addToWorkingSetButton = new Button(container, SWT.CHECK);
    GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
    gd_addToWorkingSetButton.verticalIndent = 12;
    addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
    addToWorkingSetButton.setSelection(true);
    addToWorkingSetButton.setData("name", "addToWorkingSetButton");
    addToWorkingSetButton.setText("Add project to working set");
    addToWorkingSetButton.setSelection(false);
    final Label workingsetLabel = new Label(container, SWT.NONE);
    GridData gd_workingsetLabel = new GridData();
    gd_workingsetLabel.horizontalIndent = 10;
    workingsetLabel.setLayoutData(gd_workingsetLabel);
    workingsetLabel.setEnabled(false);
    workingsetLabel.setData("name", "workingsetLabel");
    workingsetLabel.setText("Working set:");
    Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
    workingsetCombo.setEnabled(false);
    workingsetCombo.setData("name", "workingsetCombo");
    workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    _workingsetComboViewer = new ComboViewer(workingsetCombo);
    _workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public Object[] getElements(Object input) {
            if (input instanceof IWorkingSet[]) {
                return (IWorkingSet[]) input;
            } else if (input instanceof List<?>) {
                return new Object[] { input };
            } else if (input instanceof Set<?>) {
                return ((Set<?>) input).toArray();
            }
            return new IWorkingSet[0];
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    _workingsetComboViewer.setLabelProvider(new LabelProvider() {

        public void dispose() {
            _images.dispose();
            super.dispose();
        }

        @SuppressWarnings("deprecation")
        public Image getImage(Object element) {
            if (element instanceof IWorkingSet) {
                ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
                if (imageDescriptor != null) {
                    try {
                        return (Image) _images.create(imageDescriptor);
                    } catch (DeviceResourceException dre) {
                        return null;
                    }
                }
            }
            return super.getImage(element);
        }

        public String getText(Object element) {
            if (element instanceof IWorkingSet) {
                return ((IWorkingSet) element).getLabel();
            } else if (element instanceof List<?>) {
                StringBuffer sb = new StringBuffer();
                for (Object o : (List<?>) element) {
                    if (o instanceof IWorkingSet) {
                        if (sb.length() > 0) {
                            sb.append(", ");
                        }
                        sb.append(((IWorkingSet) o).getLabel());
                    }
                }
                return sb.toString();
            }
            return super.getText(element);
        }

        private ResourceManager _images = new LocalResourceManager(JFaceResources.getResources());
    });
    _workingsetComboViewer.setComparator(new ViewerComparator());
    final Button newWorkingSetButton = new Button(container, SWT.NONE);
    newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    newWorkingSetButton.setData("name", "configureButton");
    newWorkingSetButton.setText("More...");
    newWorkingSetButton.setEnabled(false);
    newWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent e) {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(_shell, true, _working_set_ids.toArray(new String[0]));
            if (dialog.open() == Window.OK) {
                IWorkingSet[] workingSets = dialog.getSelection();
                selectWorkingSets(Arrays.asList(workingSets));
            }
        }
    });
    if (selectWorkingSets(_workingSets)) {
        addToWorkingSetButton.setSelection(true);
        workingsetLabel.setEnabled(true);
        _workingsetComboViewer.getCombo().setEnabled(true);
        newWorkingSetButton.setEnabled(true);
    }
    addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
            workingsetLabel.setEnabled(addToWorkingingSet);
            _workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
            newWorkingSetButton.setEnabled(addToWorkingingSet);
            if (addToWorkingingSet) {
                updateConfiguration();
            } else {
                _workingSets.clear();
            }
        }
    });
    _workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateConfiguration();
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) List(java.util.List) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IWorkingSet(org.eclipse.ui.IWorkingSet) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

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