use of org.eclipse.n4js.ui.workingsets.WorkingSet in project n4js by eclipse.
the class AssignWorkingSetsAction method createDialog.
/**
* Creates the dialog for working set assignment.
*
* @param workingSets
* All the working set the user should be able to select from
* @param numberOfSelectedProjects
* The number of selected projects
*/
private ListSelectionDialog createDialog(Collection<WorkingSet> workingSets, int numberOfSelectedProjects) {
// Filter 'Other Projects' working set
List<WorkingSet> selectableWorkingSets = workingSets.stream().filter(set -> !set.getId().equals(WorkingSet.OTHERS_WORKING_SET_ID)).collect(Collectors.toList());
String message = String.format(DIALOG_SUBTITLE, numberOfSelectedProjects);
ListSelectionDialog dialog = new NonEmptyListSelectionDialog(site.getShell(), selectableWorkingSets, ArrayContentProvider.getInstance(), WorkingSetLabelProvider.INSTANCE, message);
dialog.setTitle(DIALOG_TITLE);
return dialog;
}
use of org.eclipse.n4js.ui.workingsets.WorkingSet 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.WorkingSet in project n4js by eclipse.
the class N4JSProjectActionGroup method evaluateSelection.
private int evaluateSelection(final Object[] array, final List<IProject> allOpenProjects) {
int status = 0;
for (int i = 0; i < array.length; i++) {
final Object curr = array[i];
if (curr instanceof IProject) {
final IProject project = (IProject) curr;
if (project.isOpen()) {
allOpenProjects.add(project);
} else {
status |= CLOSED_PROJECTS_SELECTED;
}
} else {
status |= NON_PROJECT_SELECTED;
if (curr instanceof WorkingSet) {
final int res = evaluateSelection(((WorkingSet) curr).getElements(), allOpenProjects);
status |= res;
}
}
}
return status;
}
use of org.eclipse.n4js.ui.workingsets.WorkingSet 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.WorkingSet 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);
}
Aggregations