Java Code Examples for org.eclipse.ui.IWorkingSet#setElements()

The following examples show how to use org.eclipse.ui.IWorkingSet#setElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkingSetDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void performElementRearrange(int eventDetail) {
	// only move if target isn't the other working set. If this is the case
	// the move will happenn automatically by refreshing the other working set
	if (!isOthersWorkingSet(fWorkingSet)) {
		List<Object> elements= new ArrayList<Object>(Arrays.asList(fWorkingSet.getElements()));
		elements.addAll(Arrays.asList(fElementsToAdds));
		fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
	}
	if (eventDetail == DND.DROP_MOVE) {
		ITreeSelection treeSelection= (ITreeSelection)fSelection;
		Map<IWorkingSet, List<Object>> workingSets= groupByWorkingSets(treeSelection.getPaths());
		for (Iterator<IWorkingSet> iter= workingSets.keySet().iterator(); iter.hasNext();) {
			IWorkingSet ws= iter.next();
			List<Object> toRemove= workingSets.get(ws);
			List<IAdaptable> currentElements= new ArrayList<IAdaptable>(Arrays.asList(ws.getElements()));
			currentElements.removeAll(toRemove);
			ws.setElements(currentElements.toArray(new IAdaptable[currentElements.size()]));
		}
	}
}
 
Example 2
Source File: WorkingSetConfigurationDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Rolls back changes to working sets.
 */
private void restoreChangedWorkingSets() {
	Iterator<IWorkingSet> iterator= fEditedWorkingSets.keySet().iterator();

	while (iterator.hasNext()) {
		IWorkingSet editedWorkingSet= iterator.next();
		IWorkingSet originalWorkingSet= fEditedWorkingSets.get(editedWorkingSet);

		if (editedWorkingSet.getName().equals(originalWorkingSet.getName()) == false) {
			editedWorkingSet.setName(originalWorkingSet.getName());
		}
		if (editedWorkingSet.getElements().equals(originalWorkingSet.getElements()) == false) {
			editedWorkingSet.setElements(originalWorkingSet.getElements());
		}
	}
}
 
Example 3
Source File: RemoveWorkingSetElementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IStructuredSelection selection) {
	IWorkingSet ws= getWorkingSet(selection);
	if (ws == null)
		return;
	HashSet<IAdaptable> elements= new HashSet<IAdaptable>(Arrays.asList(ws.getElements()));
	List<?> selectedElements= selection.toList();
	for (Iterator<?> iter= selectedElements.iterator(); iter.hasNext();) {
		Object object= iter.next();
		if (object instanceof IAdaptable) {
			IAdaptable[] adaptedElements= ws.adaptElements(new IAdaptable[] {(IAdaptable)object});
			if (adaptedElements.length == 1) {
				elements.remove(adaptedElements[0]);
			}
		}
	}
	ws.setElements(elements.toArray(new IAdaptable[elements.size()]));
}
 
Example 4
Source File: ConfigureWorkingSetAssignementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void add(IWorkingSet workingSet, IAdaptable adaptedElement) {
	IAdaptable[] elements= workingSet.getElements();
	IAdaptable[] newElements= new IAdaptable[elements.length + 1];
	System.arraycopy(elements, 0, newElements, 0, elements.length);
	newElements[elements.length]= adaptedElement;
	workingSet.setElements(newElements);
}
 
Example 5
Source File: JavaWorkingSetUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkElementExistence(IWorkingSet workingSet) {
	List<IAdaptable> elements= new ArrayList<IAdaptable>(Arrays.asList(workingSet.getElements()));
	boolean changed= false;
	for (Iterator<IAdaptable> iter= elements.iterator(); iter.hasNext();) {
		IAdaptable element= iter.next();
		boolean remove= false;
		if (element instanceof IJavaElement) {
			IJavaElement jElement= (IJavaElement)element;
			// If we have directly a project then remove it when it
			// doesn't exist anymore. However if we have a sub element
			// under a project only remove the element if the parent
			// project is open. Otherwise we would remove all elements
			// in closed projects.
			if (jElement instanceof IJavaProject) {
				remove= !jElement.exists();
			} else {
				final IJavaProject javaProject= jElement.getJavaProject();
				final boolean isProjectOpen= javaProject != null ? javaProject.getProject().isOpen() : true;
				remove= isProjectOpen && !jElement.exists();
			}
		} else if (element instanceof IResource) {
			IResource resource= (IResource)element;
			// See comments above
			if (resource instanceof IProject) {
				remove= !resource.exists();
			} else {
				IProject project= resource.getProject();
				remove= (project != null ? project.isOpen() : true) && !resource.exists();
			}
		}
		if (remove) {
			iter.remove();
			changed= true;
		}
	}
	if (changed) {
		workingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
	}
}
 
Example 6
Source File: WorkingSetsUtils.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
public static void organizeWorkingSetsFromExtensionDirectories(IProgressMonitor monitor) {

		IWorkbench workbench = PlatformUI.getWorkbench();
		IWorkingSetManager manager = workbench.getWorkingSetManager();

		Map<String, Set<IProject>> extToProjectMap = new HashMap<String, Set<IProject>>();

		IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
		monitor.beginTask("Creating Working Sets", allProjects.length);
		int projectsProcessed = 0;
		for (IProject project : allProjects) {
			// projects to ignore
			if (project.getName().equals("RemoteSystemsTempFiles") || project.getName().equals("platform") || project.getName().equals("config"))
			{ 
				continue;
			}
			File directory = project.getLocation().toFile().getParentFile();
			String directoryName = directory.getName();
			if (!extToProjectMap.containsKey(directoryName)) {
				extToProjectMap.put(directoryName, new HashSet<IProject>());
				extToProjectMap.get(directoryName).add(ResourcesPlugin.getWorkspace().getRoot().getProject("platform"));
				extToProjectMap.get(directoryName).add(ResourcesPlugin.getWorkspace().getRoot().getProject("config"));
			}
			extToProjectMap.get(directoryName).add(project);
			projectsProcessed++;
			monitor.worked(projectsProcessed);
		}
		monitor.done();

		// now create the working sets
		for (Entry<String, Set<IProject>> entry : extToProjectMap.entrySet()) {
			IWorkingSet existingWorkingSet = manager.getWorkingSet(entry.getKey());
			IProject[] projectsArray = entry.getValue().toArray(new IProject[entry.getValue().size()]);
			if (existingWorkingSet == null) {
				IWorkingSet workingSet = manager.createWorkingSet(entry.getKey(), projectsArray);
				manager.addWorkingSet(workingSet);
			} else {
				// Already got a Working Set with this name
				existingWorkingSet.setElements(projectsArray);
			}
		}
	}
 
Example 7
Source File: ConfigureWorkingSetAssignementAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static void remove(IWorkingSet workingSet, IAdaptable adaptedElement) {
	HashSet<IAdaptable> set= new HashSet<IAdaptable>(Arrays.asList(workingSet.getElements()));
	set.remove(adaptedElement);
	workingSet.setElements(set.toArray(new IAdaptable[set.size()]));
}