List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList
public List toList();
List
. From source file:com.nokia.s60tools.memspy.ui.views.MemSpyMainView.java
License:Open Source License
/** * getAvailableAction.//from w ww. ja v a2s . c om * @return action type that is available for item or items that are currently selected. */ private FileActionType getAvailableAction() { // get selected items IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); @SuppressWarnings("unchecked") List selectionList = selection.toList(); boolean swmtFileFound = false; boolean heapFileFound = false; // go thru selected files-list for (Object obj : selectionList) { MemSpyFileBundle bundle = (MemSpyFileBundle) obj; if (bundle.getFileType().equals("SWMT-Log")) { swmtFileFound = true; } else { heapFileFound = true; } } // if two files and no swmt files are found, compare heaps - action is available if (selectionList.size() == 2 && heapFileFound && !swmtFileFound) { return FileActionType.COMPARE_HEAPS; } // if swmt-files are found and no heap dumps are found, analyse swmt-action is available else if (swmtFileFound && selectionList.size() == 1) { return FileActionType.ANALYSE_SWMT_ONE; } else if (swmtFileFound && !heapFileFound) { return FileActionType.ANALYSE_SWMT_MULTIPLE; } // if heap one heap file is found, analyse heap - action is available else if (heapFileFound && selectionList.size() == 1) { return FileActionType.ANALYSE_HEAP; } // There are files selected, but only available action is delete. else if (selectionList.size() > 0) { return FileActionType.DELETE; } // No files selected - no actions are available return FileActionType.NONE; }
From source file:com.nokia.s60tools.memspy.ui.views.MemSpyMainView.java
License:Open Source License
/** * makeActions.//from w ww . j av a 2 s. co m * Creates actions */ private void makeActions() { launchSWMTAction = new Action() { @SuppressWarnings("unchecked") public void run() { // get selection list. IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); // ensure that selected items are swmt-logs if (!selection.isEmpty()) { List<MemSpyFileBundle> list = selection.toList(); ArrayList<String> swmtLogs = new ArrayList<String>(); boolean allFilesAreSwmtLogs = true; // Go thru bundle list and add all file paths into arraylist for (MemSpyFileBundle item : list) { swmtLogs.add(item.getFilePath()); if (item.getFileType().equals("SWMT-log")) { allFilesAreSwmtLogs = false; } } // ensure that all selected files were swmt logs if (allFilesAreSwmtLogs) { // launch swmt analyser for selected logs. SwmtAnalyser analyser = new SwmtAnalyser(MemSpyConsole.getInstance()); analyser.analyse(swmtLogs); } } } }; launchSWMTAction.setText("Launch SWMT-Analyser"); launchSWMTAction.setToolTipText("Launch SWMT-Analyser"); launchSWMTAction.setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_LAUNCH_SWMT)); compareTwoHeapsAction = new Action() { @SuppressWarnings("unchecked") public void run() { // get selected items: ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; //verify that to heap files are selected. if (getAvailableAction() == FileActionType.COMPARE_HEAPS) { compareHeaps(selectionList); } } }; compareTwoHeapsAction.setText(TOOLTIP_COMPARE_2_IMPORTED_FILE); compareTwoHeapsAction.setToolTipText(TOOLTIP_COMPARE_2_IMPORTED_FILE); compareTwoHeapsAction .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_COMPARE_2_HEAP)); importAndCompareHeapsAction = new Action() { @SuppressWarnings("unchecked") public void run() { // get selected items: ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; //verify that only one file is selected. if (getAvailableAction() == FileActionType.ANALYSE_HEAP) { importAndCompareHeaps(selectionList); } } }; importAndCompareHeapsAction.setText(TOOLTIP_TEXT_IMPORT_AND_COMPARE); importAndCompareHeapsAction.setToolTipText(TOOLTIP_TEXT_IMPORT_AND_COMPARE); importAndCompareHeapsAction .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_COMPARE_2_HEAP)); compareHeapsToolbarAction = new Action() { @SuppressWarnings("unchecked") public void run() { // get selected items: ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; // check if only one file is selected. if (getAvailableAction() == FileActionType.ANALYSE_HEAP) { importAndCompareHeaps(selectionList); } // or if two heaps are selected, then compare them. else if (getAvailableAction() == FileActionType.COMPARE_HEAPS) { compareHeaps(selectionList); } } }; compareHeapsToolbarAction.setText(TOOLTIP_COMPARE_2_IMPORTED_FILE); compareHeapsToolbarAction.setToolTipText(TOOLTIP_COMPARE_2_IMPORTED_FILE); compareHeapsToolbarAction .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_COMPARE_2_HEAP)); launchHeapAnalyserAction = new Action() { @SuppressWarnings("unchecked") public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; // Get thread name from xml-file String xmlFile = selectionList.get(0).getXMLFilePath(); AnalyserXMLGenerator xml = readXMLFile(xmlFile); //If Symbol files has not been set to data, before analyze, user have to set a Symbol file if (!xml.hasXMLDebugMetaDataFile()) { //verify that only one file is selected. if (selectionList.size() == 1) { //Make user to edit symbol files, and after that, continue to launch int retCode = runWizard(MemSpyWizardType.SYMBOLS, xml); //Don't giving an error message if user presses Cancel, instead just return if (retCode == Window.CANCEL) { return; } } } String threadName = xml.getXMLThreadName(); //verify that only one file is selected. if (selectionList.size() == 1) { //verify that heap dump file is selected. if (selectionList.get(0).hasHeapDumpFile()) { // get xml files path String xmlPath = xmlFile; // launch heap analyser launchHeapAnalyser(xmlPath, null, threadName, true); } } } }; launchHeapAnalyserAction.setText("Analyse selected heap with Heap Analyser"); launchHeapAnalyserAction.setToolTipText("Analyse selected heap with Heap Analyser"); launchHeapAnalyserAction .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_ANALYZE_HEAP)); launchWizardAction = new Action() { public void run() { runWizard(MemSpyWizardType.FULL, null); } }; launchWizardAction.setText("Launch MemSpy's import Wizard"); launchWizardAction.setToolTipText("Launch MemSpy's import Wizard"); launchWizardAction.setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.IMG_APP_ICON)); doubleClickAction = new Action() { public void run() { FileActionType action = getAvailableAction(); switch (action) { case ANALYSE_HEAP: { launchHeapAnalyserAction.run(); break; } case ANALYSE_SWMT_ONE: case ANALYSE_SWMT_MULTIPLE: { launchSWMTAction.run(); break; } case COMPARE_HEAPS: { compareTwoHeapsAction.run(); break; } default: { // No need to do anything with other action. break; } } } }; deleteAction = new Action() { @SuppressWarnings("unchecked") public void run() { // get selected items: ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; // ensure that some item(s) is selected. if (selectionList.size() >= 1) { // Display a Confirmation dialog MessageBox messageBox = new MessageBox(viewer.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setText("MemSpy - Delete Files"); messageBox.setMessage("Are you sure you want to delete selected files?"); int buttonID = messageBox.open(); if (buttonID == SWT.YES) { for (MemSpyFileBundle item : selectionList) { // delete it item.delete(); } refreshContentAndView(); } } } }; deleteAction.setText("Delete"); deleteAction.setToolTipText("Delete selected item"); deleteAction.setImageDescriptor( PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); openFile = new Action() { @SuppressWarnings("unchecked") public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; //verify that only one file is selected. if (selectionList.size() == 1) { // open selected log file in editor. File fileToOpen = new File(selectionList.get(0).getFilePath()); if (fileToOpen.exists() && fileToOpen.isFile()) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI()); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { IDE.openEditorOnFileStore(page, fileStore); } catch (PartInitException e) { showErrorMessage(ERROR_TOPIC, "MemSpy was unable to open file."); } } else { showErrorMessage(ERROR_TOPIC, "File does not exists."); } } } }; openFile.setText("Open selected file in text editor"); openFile.setToolTipText("Open selected file in text editor"); editSymbols = new Action() { @SuppressWarnings("unchecked") public void run() { ISelection selection = viewer.getSelection(); Object obj = ((IStructuredSelection) selection).toList(); List<MemSpyFileBundle> selectionList = (List<MemSpyFileBundle>) obj; //verify that only one file is selected. if (selectionList.size() == 1) { AnalyserXMLGenerator info = readXMLFile(selectionList.get(0).getXMLFilePath()); runWizard(MemSpyWizardType.SYMBOLS, info); } } }; editSymbols.setText("Edit symbol definitions of selected Heap Dump"); editSymbols.setToolTipText("Edit symbol definitions of selected Heap Dump"); }
From source file:com.nokia.s60tools.ui.actions.CopyFromTableViewerAction.java
License:Open Source License
@SuppressWarnings("unchecked") //$NON-NLS-1$ public void run() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); List<Object> objList = selection.toList(); for (int i = 0; i < copyHandlerArr.length; i++) { ICopyActionHandler handler = copyHandlerArr[i]; if (handler.acceptAndCopy(objList)) { // Handler accepted the input break; }//from ww w .ja va 2 s . co m } }
From source file:com.nokia.sdt.uidesigner.ui.actions.CutActionCommandHandler.java
License:Open Source License
public boolean updateSelection(IStructuredSelection selection) { List filteredSelection = new ArrayList(); for (Iterator iter = selection.iterator(); iter.hasNext();) { EditPart part = (EditPart) iter.next(); if (helper.isRemovablePart(part) && !isDescendantOfSelectedPart(part, selection.toList())) filteredSelection.add(part); }/* w ww .j a v a 2s.c o m*/ if (filteredSelection.isEmpty()) return false; // can't execute return super.updateSelection(new StructuredSelection(filteredSelection)); }
From source file:com.nokia.sdt.uidesigner.ui.actions.PasteActionCommandHandler.java
License:Open Source License
public void run() { IStructuredSelection structuredSelection = getStructuredSelection(); Collection selectedObjects = helper.makeEObjectList(structuredSelection.toList()); EObject owner = null;// w ww .j a v a 2 s . c o m if (selectedObjects.size() > 1) { owner = EditorUtils.getCommonDirectParent(selectedObjects); } else if (!selectedObjects.isEmpty()) { // size == 1 owner = (EObject) selectedObjects.iterator().next(); // special case where owner is not a container, use the parent of the owner if (Adapters.getContainer(owner) == null) { owner = Adapters.getComponentInstance(owner).getParent(); } } // try the content container, first if (owner == null) { owner = helper.editor.getDisplayModel().getContentContainer(); } // else try the root container if (owner == null) { owner = helper.getRootContainer(); } // preflight, in case we need to try the parent Collection clipboard = helper.editor.getDataModel().getEditingDomain().getClipboard(); List<IStatus> statuses = new ArrayList(); if (!EditorUtils.canContainAtLeastOneComponent(owner, clipboard, statuses)) { // if can't paste even one object, try the owner's parent (just one level) IComponentInstance ownerInstance = Adapters.getComponentInstance(owner); EObject parent = null; if (ownerInstance != null) parent = ownerInstance.getParent(); if (parent != null) owner = parent; if (!EditorUtils.canContainAtLeastOneComponent(owner, clipboard, statuses)) { StatusBuilder builder = new StatusBuilder(UIDesignerPlugin.getDefault()); MultiStatus multiStatus = builder.createMultiStatus( Strings.getString("PasteActionCommandHandler.CouldNotAddComponentsError"), new Object[0]); //$NON-NLS-1$ for (Iterator<IStatus> iter = statuses.iterator(); iter.hasNext();) multiStatus.add(iter.next()); Logging.showErrorDialog(null, Strings.getString("PasteActionCommandHandler.PasteFailedTitle"), //$NON-NLS-1$ multiStatus); owner = null; } } if (owner != null) { Command dataModelCommand = getDataModelCommand(owner); helper.doExecute(dataModelCommand); EditorUtils.setSelectionToAffectedObjects(helper.editor, dataModelCommand.getAffectedObjects()); } }
From source file:com.nokia.tools.s60.editor.Series60ContentOutlinePage.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { if (getEditorPart() == null) { return;//from ww w . j av a 2 s. c om } if (!isViewerDispatching && event.getSource() == categoryViewer) { isCategoryDispatching = true; try { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); List selectedEditParts = selection.toList(); List<Object> treeParts = new ArrayList<Object>(selectedEditParts.size()); List<Object> graphicalParts = new ArrayList<Object>(selectedEditParts.size()); for (Object obj : selectedEditParts) { if (obj instanceof TreeEditPart) { treeParts.add(obj); } else if (obj instanceof GraphicalEditPart) { graphicalParts.add(obj); } } if (!treeParts.isEmpty()) { getViewer().setSelection(new StructuredSelection(treeParts)); } if (!graphicalParts.isEmpty()) { GraphicalViewer viewer = (GraphicalViewer) getEditorPart().getAdapter(GraphicalViewer.class); if (viewer != null) { viewer.setSelection(new StructuredSelection(graphicalParts)); } } /* synchronize selection in editor with this */ List newSelection = new ArrayList(); for (Iterator iter = selection.iterator(); iter.hasNext();) { TreeNode node = (TreeNode) iter.next(); IScreenElement screenElem = null; if (node.getContent() instanceof IScreenElement) { screenElem = (IScreenElement) node.getContent(); } else if (node.getContent() instanceof IContentData) { TreeNode last = node; while (last.getChildren().size() == 1) { last = last.getChildren().iterator().next(); } if (last.getContent() instanceof IScreenElement) { screenElem = (IScreenElement) last.getContent(); } } if (screenElem != null && getViewer() != null) { EditPart part = (EditPart) getViewer().getEditPartRegistry().get(screenElem.getWidget()); if (part != null) { newSelection.add(part); } } } if (getViewer() != null) { if (!newSelection.isEmpty()) { getViewer().setSelection(new StructuredSelection(newSelection)); } else { getViewer().deselectAll(); } } } finally { isCategoryDispatching = false; } } else if (!isCategoryDispatching && event.getSource() == getEditorPart().getAdapter(GraphicalViewer.class)) { isViewerDispatching = true; try { List selectedParts = ((IStructuredSelection) event.getSelection()).toList(); List newSelection = new ArrayList(); for (Object part : selectedParts) { EObject model = (EObject) ((EditPart) part).getModel(); IScreenElement data = (IScreenElement) JEMUtil.getScreenElement(model); if (data != null) { // data can be null when the freeform is selected if (data.getWidget() != model) { IScreenElement[] elems = (IScreenElement[]) data.getData() .getAdapter(IScreenElement[].class); if (elems != null) { for (int i = 0; i < elems.length; i++) { IScreenElement elem = elems[i]; if (elem.getWidget() == model) { data = elem; break; } } } } TreeNode root = (TreeNode) categoryViewer.getInput(); if (root != null) { TreeNode node = findNode(root, data); if (node != null) { newSelection.add(node); categoryViewer.expandToLevel(node, 0); } } } } categoryViewer.setSelection(new StructuredSelection(newSelection)); } finally { isViewerDispatching = false; } } }
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
/** * Called from resource view to set icon-set to be displayed *///from w w w. j a v a 2 s .c o m public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (!listenOnSelection || part instanceof IconView) { return; } // selections from resource viewer // if (part instanceof ResourceViewPart || part == null) { // if (selection instanceof IStructuredSelection && !(part instanceof // IconView)) { if (selection instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) selection; if (sel.size() == 0) { return; } // convert edit parts to content data // filters out the duplicates Set<Object> set = new HashSet<Object>(sel.size()); for (Object object : sel.toArray()) { IContentData data = null; if (object instanceof EditPart || object instanceof IScreenElement) { data = findModelItem(object); } else if (object instanceof IContentData) { data = (IContentData) object; } if (data != null) { ISkinnableEntityAdapter ca = (ISkinnableEntityAdapter) data .getAdapter(ISkinnableEntityAdapter.class); if (ca != null) { // cares only about the skinnable entities set.add(data); } } } if (set.isEmpty()) { // clears the view initializePage(StructuredSelection.EMPTY, null, null); repopulateContents(StructuredSelection.EMPTY); return; } List<Object> cdSel = new ArrayList<Object>(set.size()); for (Object obj : set) { cdSel.add(obj); } // selection raised from editor, // editor if (part == sourceEditor) { cdSel.add(Boolean.FALSE); } sel = new StructuredSelection(cdSel); List<Object> newSelection = new ArrayList<Object>(); if (ctrl_active || shift_active) { // preserve selection // add non-visible elements from current component view // selection List<IContentData> nonVisuals = new ArrayList<IContentData>(); for (int i = 0; selectedItems != null && i < selectedItems.size(); i++) { IContentData data = selectedItems.get(i); if (!isVisibleOnScreen(data)) { nonVisuals.add(data); } } List<Object> _selection = new ArrayList<Object>(); _selection.addAll(Arrays.asList(sel.toArray())); if (selectedItems != null) { newSelection.addAll(selectedItems); } // add added elements for (int i = 0; i < _selection.size(); i++) { Object obj = _selection.get(i); if (!newSelection.contains(obj) || obj instanceof Boolean) { newSelection.add(obj); } } // remove removed elements for (int i = 0; selectedItems != null && i < selectedItems.size(); i++) { Object obj = selectedItems.get(i); if (!_selection.contains(obj)) { // preserve non-visible if (!nonVisuals.contains(obj)) { newSelection.remove(obj); } } } } else { newSelection = sel.toList(); } final StructuredSelection newSel = new StructuredSelection(newSelection); if (sel.size() == 0 || (sel.size() > 0 && sel.getFirstElement() instanceof IContentData)) { IContentData tmpData = (IContentData) (sel.getFirstElement()); if (tmpData != null && (tmpData.getParent() instanceof IContent || tmpData.getAdapter(IScreenAdapter.class) != null) || tmpData instanceof ThemeScreenReferData) { return; } IContentAdapter adapter = (IContentAdapter) sourceEditor.getAdapter(IContentAdapter.class); IContent content = ScreenUtil.getPrimaryContent(adapter.getContents()); if (tmpData != null && !(tmpData.getRoot() instanceof IContent)) { // removed from the content tmpData = content.findById(tmpData.getId()); } final IContentData newCategory = sel.size() == 0 || tmpData == null ? null : tmpData.getParent(); com.nokia.tools.platform.core.Display newDisplay = (com.nokia.tools.platform.core.Display) content .getAttribute(ContentAttribute.DISPLAY.name()); final Dimension newResolution = newDisplay == null ? null : new Dimension(newDisplay.getWidth(), newDisplay.getHeight()); if (currentCategory != newCategory || (newResolution != null && !newResolution.equals(resolution)) || currentCategory == null || getItems().size() != container.getChildren().length) { initializePage(newSel, newCategory, newResolution); Display.getDefault().asyncExec(new Runnable() { public void run() { repopulateContents(newSel); } }); return; } } // always sets the selection because the selection on the main // editor might have changed setSelection(newSel); } }
From source file:com.nokia.tools.s60ct.confml.actions.OpenConfmlAction.java
License:Open Source License
private void takeSettingsFromSelection(ISelection selection) { selectedObjects.clear();/* ww w. j ava2 s . c om*/ if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; List<?> list = ss.toList(); selectedObjects = new ArrayList<ESetting>(); for (int i = 0; i < list.size(); i++) { Object o = list.get(i); if (o instanceof ESimpleSetting) { ESimpleSetting setting = (ESimpleSetting) o; selectedObjects.add(setting); } else if (o instanceof EResourceSetting) { EResourceSetting setting = (EResourceSetting) o; selectedObjects.add(setting); } else if (o instanceof ESimpleValue) { ESimpleValue sVal = (ESimpleValue) o; selectedObjects.add(sVal.getType()); } else if (o instanceof EResourceValue) { EResourceValue resVal = (EResourceValue) o; selectedObjects.add(resVal.getLocalPath().getType()); } } } }
From source file:com.nokia.tools.s60ct.confml.actions.OpenConfmlAction.java
License:Open Source License
private boolean shouldBeEnabled(IStructuredSelection ss) { List<?> list = ss.toList(); for (Object object : list) { if (object instanceof ESimpleSetting) { return true; }/* www . ja v a 2 s.co m*/ if (object instanceof ESimpleValue) { return true; } else if (object instanceof EResourceSetting) { return true; } } return false; }
From source file:com.nokia.tools.s60ct.confml.actions.OpenImplementationAction.java
License:Open Source License
private boolean shouldBeEnabled(IStructuredSelection ss) { List<?> list = ss.toList(); for (Object object : list) { if (object instanceof ESimpleSetting) { URI uri = getURI((ESimpleSetting) object, ss.getFirstElement()); if (uri != null) return true; }//from ww w .j a v a2 s. c o m if (object instanceof ESimpleValue) { URI uri = getURI(((ESimpleValue) object).getType(), ss.getFirstElement()); if (uri != null) return true; } else if (object instanceof EResourceSetting) { URI uri = getURI(((EResourceSetting) object).getLocalPath(), ss.getFirstElement()); if (uri != null) return true; } } return false; }