List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.nokia.tools.variant.editor.actions.RemoveSequenceItemsAction.java
License:Open Source License
@Override public void initSelectionListener() { selectionListener = new ISelectionListener() { public void selectionChanged(IWorkbenchPart part, ISelection selection) { setEnabled(false);//from w w w. j a v a2 s.c o m if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { Set<Object> set = new HashSet<Object>(); Object[] array = ss.toArray(); Boolean setDisabled = false; for (int i = 0; i < array.length; i++) { Object o = array[i]; if (o instanceof SimpleSetting || o instanceof FileSystemEntrySetting) { SequenceSetting relatedSequenceSetting = findSeqSetting((EObject) o); if (relatedSequenceSetting != null) { set.add(relatedSequenceSetting); if (widget == null) { setEnabled(true); } else { if (!widget.isDisposed() && widget.getData() instanceof UISetting) { Setting setting = ((UISetting) widget.getData()).getSetting(); if (setting == relatedSequenceSetting) { setEnabled(true); } } } } else { setEnabled(false); return; } } else { setDisabled = true; } if ((set.size() > 1) || setDisabled) { setEnabled(false); return; } } } } } }; }
From source file:com.nokia.tools.variant.editor.editors.CPFEditor.java
License:Open Source License
private ISelection convertSelectionToMainModel(IStructuredSelection selection) { List<Object> list = new ArrayList<Object>(); Object[] array = selection.toArray(); for (Object object : array) { if (object instanceof UIGroup) { UIGroup uiGroup = (UIGroup) object; Object model = uiGroup.getModel(); if (model != null) { list.add(model);//from w w w .j a va 2s. c o m } } else if (object instanceof UISetting) { UISetting uiSetting = (UISetting) object; Setting setting = uiSetting.getSetting(); if (setting != null) { list.add(setting); } } else if (object instanceof IStorage) { List<IStorage> list2 = new ArrayList<IStorage>(); list2.add((IStorage) object); return new StructuredSelection(list2); } else if (object instanceof UIElement) { UIElement uiElement = (UIElement) object; return new StructuredSelection(uiElement); } } return new StructuredSelection(list); }
From source file:com.nokia.tools.variant.editor.editors.CPFEditor.java
License:Open Source License
protected ISelection convertSelectionToUIModel(IStructuredSelection selection) { List<UISetting> list = new ArrayList<UISetting>(); Object[] array = selection.toArray(); for (Object object : array) { if (object instanceof Setting) { Setting setting = (Setting) object; UISetting uiSetting = getUISetting(setting); if (uiSetting != null) { list.add(uiSetting);/* w w w. j a v a 2 s . c o m*/ } } else if (object instanceof ResourceStorage) { List<ResourceStorage> list2 = new ArrayList<ResourceStorage>(); list2.add((ResourceStorage) object); return new StructuredSelection(list2); } else if (object instanceof UIElement) { UIElement uiElement = (UIElement) object; return new StructuredSelection(uiElement); } } return new StructuredSelection(list); }
From source file:com.nokia.tools.variant.resourcelibrary.actions.CopyResourceAction.java
License:Open Source License
@Override public void run() { CommandStack stack = page.getCommandStack(); IStructuredSelection sel = getStructuredSelection(); List<ResourceStorage> resources = new ArrayList<ResourceStorage>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { resources.add((ResourceStorage) obj); }//from w w w . jav a 2 s. com } Shell shell = ((IPage) page).getControl().getShell(); ResourcePickDialog dialog = new ResourcePickDialog(shell, true, "", resources); if (dialog.open() != IDialogConstants.OK_ID) { return; } Object result = dialog.getFirstResult(); // target file/folder if (result instanceof Directory) { Directory target = (Directory) result; List<FileSystemElement> sources = new ArrayList<FileSystemElement>(); for (ResourceStorage storage : resources) { sources.add(storage.getFileSystemElement()); } Command command; if (sources.size() == 1) { command = CopyResourcesCommand.createCopyCommand(target, sources.get(0), dialog.getFileName()); } else { command = CopyResourcesCommand.createCopyCommand(target, sources); } if (command.canExecute()) { stack.execute(command); } else { command.dispose(); } } }
From source file:com.nokia.tools.variant.resourcelibrary.actions.CreateFolderAction.java
License:Open Source License
@Override public void run() { CommandStack stack = page.getCommandStack(); IStructuredSelection sel = getStructuredSelection(); List<ResourceStorage> resources = new ArrayList<ResourceStorage>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { resources.add((ResourceStorage) obj); }/*ww w . j av a 2 s . c o m*/ } Shell shell = SWTUtil.getStandardDisplay().getActiveShell(); // Fetch selection Object element = sel.getFirstElement(); FileSystemElement fse = null; if (element instanceof ResourceStorage) { fse = ((ResourceStorage) element).getFileSystemElement(); } else if (element == null) { fse = page.getResourceModelRoot(); } if (!(fse instanceof Directory)) { return; } Directory target = (Directory) fse; // Launch a dialog for fetching folder, check existence of the folder CreateFolderDialog diag = new CreateFolderDialog(shell, target); if (diag.open() != CreateFolderDialog.OK) { return; } String folderName = (String) diag.getFirstResult(); Command cmd = CreateFolderCommand.createNewDirectoryCommand(target, new Path(folderName)); if (cmd.canExecute()) { stack.execute(cmd); } else { cmd.dispose(); } }
From source file:com.nokia.tools.variant.resourcelibrary.actions.DeleteResourceAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { if (selection.isEmpty()) { return false; }// w w w. jav a 2s. c om for (Object obj : selection.toArray()) { if (!(obj instanceof ResourceStorage)) { return false; } FileSystemElement element = ((ResourceStorage) obj).getFileSystemElement(); if (ResourceLibraryCommandHelper.checkModifyStatus(element) != ResourceLibraryCommandHelper.STATUS_OK || element.touchedByReadonlySetting()) { return false; } } return true; }
From source file:com.nokia.tools.variant.resourcelibrary.actions.DeleteResourceAction.java
License:Open Source License
@Override public void run() { CommandStack stack = page.getCommandStack(); IStructuredSelection sel = getStructuredSelection(); List<ResourceStorage> resources = new ArrayList<ResourceStorage>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { resources.add((ResourceStorage) obj); }/*from w w w.j av a2s . co m*/ } Shell shell = SWTUtil.getStandardDisplay().getActiveShell(); // Fetch a handle for progress monitor List<FileSystemElement> elements = new ArrayList<FileSystemElement>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { FileSystemElement element = ((ResourceStorage) obj).getFileSystemElement(); elements.add(element); } } Command command = RemoveCommand.createResourceRemove(elements); if (command.canExecute()) { // Warn the user MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); messageBox.setText("Deleting resources"); messageBox.setMessage(DELETE_CONFIRMATION_STRING); if (messageBox.open() != SWT.OK) { command.dispose(); return; } stack.execute(command); } else { command.dispose(); } }
From source file:com.nokia.tools.variant.resourcelibrary.actions.ImportResourceAction.java
License:Open Source License
@Override public void run() { CommandStack stack = page.getCommandStack(); IStructuredSelection sel = getStructuredSelection(); List<ResourceStorage> resources = new ArrayList<ResourceStorage>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { resources.add((ResourceStorage) obj); }/*from w w w . java2s . c o m*/ } Shell shell = SWTUtil.getStandardDisplay().getActiveShell(); // Open a dialog for importing file List<File> files = getImportedFiles(shell); if (files == null || files.isEmpty()) { return; } // Fetch destination for the file Directory destination = getDestination(sel); // Assume destination is a directory, create local representation if (destination == null) { return; } assert (destination != null); Command command = ImportCommand.createImportCommand(destination, files); if (command.canExecute()) { stack.execute(command); } else { command.dispose(); } }
From source file:com.nokia.tools.variant.resourcelibrary.actions.MoveResourceAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { if (selection.isEmpty()) { return false; }//from ww w .j a v a2 s . c om for (Object obj : selection.toArray()) { if (!(obj instanceof ResourceStorage)) { return false; } FileSystemElement fse = ((ResourceStorage) obj).getFileSystemElement(); if (ResourceLibraryCommandHelper.checkModifyStatus(fse) != ResourceLibraryCommandHelper.STATUS_OK || fse.touchedByReadonlySetting()) { return false; } } return true; }
From source file:com.nokia.tools.variant.resourcelibrary.actions.MoveResourceAction.java
License:Open Source License
@Override public void run() { CommandStack stack = page.getCommandStack(); IStructuredSelection sel = getStructuredSelection(); List<ResourceStorage> resources = new ArrayList<ResourceStorage>(); for (Object obj : sel.toArray()) { if (obj instanceof ResourceStorage) { resources.add((ResourceStorage) obj); }//w ww . j a v a2 s. com } Shell shell = ((IPage) page).getControl().getShell(); ResourcePickDialog dialog = new ResourcePickDialog(shell, true, "", resources); if (dialog.open() != IDialogConstants.OK_ID) { return; } Object result = dialog.getFirstResult(); // target file/folder if (result instanceof Directory) { Directory target = (Directory) result; List<FileSystemElement> sources = new ArrayList<FileSystemElement>(); for (ResourceStorage storage : resources) { sources.add(storage.getFileSystemElement()); } Command command = MoveCommand.createMoveCommand(target, sources); if (command.canExecute()) { stack.execute(command); } else { command.dispose(); } } }