use of org.eclipse.n4js.ui.workingsets.WorkingSetManager in project n4js by eclipse.
the class AssignWorkingSetsAction method performWorkingSetUpdate.
/**
* Performs the working sets update specified by the given dialog result.
*
* @param dialogResult
* The result of the list selection dialog.
* @param selectionProjectNames
* A list of names of the selected projects
* @returns {@code true} if the update was successfully performed. {@code false} otherwise.
*/
private boolean performWorkingSetUpdate(Object[] dialogResult, Iterable<String> selectionProjectNames) {
if (dialogResult == null) {
return false;
}
WorkingSetManager workingSetManager = broker.getActiveManager();
if (!(workingSetManager instanceof ManualAssociationAwareWorkingSetManager)) {
return false;
}
// get copies of the workspace working sets.
List<WorkingSet> allWorkingSets = new ArrayList<>(Arrays.asList(workingSetManager.getAllWorkingSets()));
List<WorkingSet> workingSets = new ArrayList<>(Arrays.asList(workingSetManager.getWorkingSets()));
// build WorkingSet edit difference
WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(workingSetManager);
for (Object resultItem : dialogResult) {
// abort if the dialog returned a non-working-set item
if (!(resultItem instanceof ManualAssociationWorkingSet)) {
return false;
}
ManualAssociationWorkingSet oldState = (ManualAssociationWorkingSet) resultItem;
ManualAssociationWorkingSet newState = getWorkingSetWithAddedProjects(oldState, selectionProjectNames);
// register working set edit
builder.edit(oldState, newState);
// replace working set with its new state
replaceWorkingSet(workingSets, newState);
replaceWorkingSet(allWorkingSets, newState);
}
// apply WorkingSet update and refresh UI
workingSetManager.updateState(builder.build(workingSets, allWorkingSets));
broker.refreshNavigator();
return true;
}
use of org.eclipse.n4js.ui.workingsets.WorkingSetManager in project n4js by eclipse.
the class N4JSProjectInWorkingSetDropAdapterAssistant method validateDrop.
@Override
public IStatus validateDrop(Object target, int operation, TransferData transferType) {
// We don't currently support COPY or LINK
if (operation != DND.DROP_MOVE) {
return CANCEL_STATUS;
}
WorkingSet targetWorkingSet = null;
if (target instanceof WorkingSet) {
targetWorkingSet = (WorkingSet) target;
}
if (targetWorkingSet == null) {
return CANCEL_STATUS;
}
if (!LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
return CANCEL_STATUS;
}
// Verify that we have at least one project not already in the target
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object item : ((IStructuredSelection) selection).toArray()) {
if (item instanceof IAdaptable) {
IProject project = ((IAdaptable) item).getAdapter(IProject.class);
if (project != null && !workingSetContains(targetWorkingSet, project)) {
WorkingSetManager manager = ((WorkingSet) target).getWorkingSetManager();
if (ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
return OK_STATUS;
}
}
}
}
// Or contains exactly one working set for rearrange purposes.
final Object[] elements = ((IStructuredSelection) selection).toArray();
if (elements.length == 1 && elements[0] instanceof WorkingSet) {
getCommonDropAdapter().setExpandEnabled(false);
getCommonDropAdapter().setFeedbackEnabled(true);
return OK_STATUS;
}
}
return CANCEL_STATUS;
}
use of org.eclipse.n4js.ui.workingsets.WorkingSetManager in project n4js by eclipse.
the class N4JSResourceExtensionSorter method compareClass.
@Override
@SuppressWarnings({ "deprecation" })
protected int compareClass(Object e1, Object e2) {
if (e1 instanceof ResourceNode && e2 instanceof ResourceNode) {
final File f1 = ((ResourceNode) e1).getResource();
final File f2 = ((ResourceNode) e2).getResource();
if (f1.isFile() == f2.isFile()) {
return getComparator().compare(f1.getName(), f2.getName());
} else if (f1.isDirectory() && f2.isFile()) {
return -1;
} else if (f1.isFile() && f2.isDirectory()) {
return 1;
}
} else if (e1 instanceof WorkingSet && e2 instanceof WorkingSet) {
final WorkingSetManager workingSetManager = workingSetManagerBroker.getActiveManager();
if (null != workingSetManager) {
final WorkingSet ws1 = (WorkingSet) e1;
final WorkingSet ws2 = (WorkingSet) e2;
return workingSetManager.compare(ws1, ws2);
}
}
return super.compareClass(e1, e2);
}
use of org.eclipse.n4js.ui.workingsets.WorkingSetManager in project n4js by eclipse.
the class SelectWorkingSetDropDownAction method createMenuItems.
@Override
protected void createMenuItems(final Menu parent) {
final Collection<WorkingSetManager> managers = workingSetManagerBroker.getWorkingSetManagers();
for (final WorkingSetManager manager : managers) {
final MenuItem item = new MenuItem(parent, CHECK);
item.setText(manager.getLabel());
item.setImage(manager.getImage().orNull());
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
workingSetManagerBroker.setActiveManager(manager);
}
});
item.setSelection(workingSetManagerBroker.isActiveManager(manager));
}
final WorkingSetManager activeManager = workingSetManagerBroker.getActiveManager();
if (null != activeManager) {
createSeparator(parent);
final MenuItem item = new MenuItem(parent, CHECK);
item.setText("Configure " + activeManager.getLabel() + "...");
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
activeManager.configure();
workingSetManagerBroker.refreshNavigator();
}
});
}
}
use of org.eclipse.n4js.ui.workingsets.WorkingSetManager in project n4js by eclipse.
the class ShowHiddenWorkingSetsDropDownAction method createMenuItems.
@Override
protected void createMenuItems(final Menu parent) {
final WorkingSetManager manager = workingSetManagerBroker.getActiveManager();
final WorkingSet[] allWorkingSets = manager.getAllWorkingSets();
final WorkingSet[] workingSets = manager.getWorkingSets();
for (final WorkingSet workingSet : allWorkingSets) {
if (!Arrays.contains(workingSets, workingSet)) {
final MenuItem item = new MenuItem(parent, PUSH);
item.setText(workingSet.getName());
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
showWorkingSet(manager, workingSet);
}
});
}
}
createSeparator(parent);
final MenuItem item = new MenuItem(parent, CHECK);
item.setText(SHOW_ALL_HIDDEN_WORKING_SETS);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
final Iterable<WorkingSet> difference = difference(newHashSet(allWorkingSets), newHashSet(workingSets));
final WorkingSet[] toShow = Iterables.toArray(difference, WorkingSet.class);
showWorkingSet(manager, toShow);
}
});
}
Aggregations