List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
protected void repopulateContents(final IStructuredSelection ssel) { // keeps the last selection, so we can refresh the entire category when // some children have been added or removed lastSelection = ssel;/* w ww . j ava2 s. co m*/ for (EditObject resource : resources) { ComponentAdapter adapter = (ComponentAdapter) EcoreUtil.getExistingAdapter(resource, ComponentAdapter.class); resource.eAdapters().remove(adapter); } resources.clear(); if (container == null || container.isDisposed()) { return; } clearArea(); Set<IContentData> selection = new HashSet<IContentData>(); if (ssel != null) { for (Iterator iter = ssel.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof IContentData) { selection.add((IContentData) obj); } } } List<Object> newSelection = new ArrayList<Object>(); // populate all leafs of category try { List<IContentData> childrenList = getItems(); for (final IContentData child : childrenList) { final ImageLabel control = new ImageLabel(container, SWT.NONE); control.setUnselectedBackground(container.getBackground()); control.setSelectedBackground(container.getBackground()); control.setData(child); control.addKeyListener(IconViewPage.this); EditObject resource = (EditObject) child.getAdapter(EditObject.class); resource.eAdapters().add(new ComponentAdapter(control)); resources.add(resource); IContentData parent = child.getParent(); if (parent != null) { EditObject parentResource = (EditObject) parent.getAdapter(EditObject.class); if (parentResource != null && EcoreUtil.getExistingAdapter(parentResource, ComponentAdapter.class) == null) { parentResource.eAdapters().add(new ComponentAdapter(null)); resources.add(parentResource); } } if (toggleTextAction != null) { control.setLines(toggleTextAction.isChecked() ? IS60IDEConstants.IMAGE_LABEL_TEXT_LINES : 0); } ISkinnableEntityAdapter ska = (ISkinnableEntityAdapter) child .getAdapter(ISkinnableEntityAdapter.class); control.setModified(ska != null && ska.isSkinned()); ISkinnableContentDataAdapter scda = (ISkinnableContentDataAdapter) child .getAdapter(ISkinnableContentDataAdapter.class); if (scda != null) { control.setModified(scda.isElementSkinned()); control.redraw(); } if (selection.contains(child)) { newSelection.add(child); control.setSelected(true); } mouseRightClicked = false; // look if we can get right image, if not, // get default control.setImageDescriptor(getImageDescriptor(child)); control.setText(child.getName()); IconTooltip tooltip = new IconTooltip(findScreenData(child), this, getCommandStack()); control.setData(tooltip.getClass().getName(), tooltip); if (tooltip.getContributionsCount(false) == 0) { // no tooltip contribution // so use standard tooltip control.setToolTipText(child.getName()); } else { tooltip.setControl(control); } control.addSelectionListener(new ImageLabel.SelectedListener() { public void selected(EventObject e) { if (!selectedItems.contains(((ImageLabel) e.getSource()).getData())) { ((ImageLabel) e.getSource()).setSelected(false); } } }); control.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { mouseButtonDown(e); if (e.button == 3) { mouseRightClicked = true; } final IconTooltip tooltip = (IconTooltip) control.getData(IconTooltip.class.getName()); if (tooltip != null) { if (e.button == 3) { tooltip.hide(); } tooltip.disable(); Display.getDefault().asyncExec(new Runnable() { public void run() { if (tooltip != null) { tooltip.enable(); } } }); } } @Override public void mouseUp(MouseEvent e) { if (mouseButtonUp(e)) { return; } if (e.button == 1) { if (ctrl_active && shift_active) { updateSelection(child, SelectionMode.CTRL_SHIFT); } else if (shift_active) { updateSelection(child, SelectionMode.SHIFT); } else if (ctrl_active) { updateSelection(child, SelectionMode.CTRL); } else { selectionStart = child; selfSetSelection(new StructuredSelection(child)); } } else if (e.button == 3) { if (selectedItems == null || !selectedItems.contains(child)) { selectionStart = child; updateSelection(child, SelectionMode.NORMAL); } } mouseRightClicked = false; } @Override public void mouseDoubleClick(MouseEvent e) { if (e.count == 2) { handleDoubleClick(child); } } }); MouseMoveListener mouseMoveListener = new MouseMoveListener() { public void mouseMove(MouseEvent e) { mouseMoved(e); } }; control.addMouseMoveListener(mouseMoveListener); MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { IIconMenuProvider imp = (IIconMenuProvider) sourceEditor .getAdapter(IIconMenuProvider.class); if (imp != null) { imp.fillIconContextMenu(manager, IconViewPage.this.parent, "components", getCommandStack(), getSite().getActionBars()); } } }); Menu menu = menuMgr.createContextMenu(control); control.setMenu(menu); // drag and drop support addDragDropSupport(control, child); } if (container != null && !container.isDisposed()) { container.layout(); scrollableComposite.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT)); container.redraw(); } } catch (Exception e) { e.printStackTrace(); } // add flags about synchronize with editor if (ssel.size() > 0 && ssel.toArray()[ssel.size() - 1] == Boolean.FALSE) newSelection.add(Boolean.FALSE); setSelection(new StructuredSelection(newSelection)); }
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 *//* ww w .ja 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.s60.views.IconViewPage.java
License:Open Source License
public void setSelection(final ISelection selection) { if (container == null || container.isDisposed()) { return;// w w w . j a v a 2 s. c o m } if (suppressSelectEvent) { return; } if (currentCategory == null) { refreshIconViewActionsState(); return; } if (selection instanceof IStructuredSelection) { final IStructuredSelection sselection = (IStructuredSelection) selection; /** * Should not be used as then when selection changes in editor the * same element can not be reselected but have to visit other * element first */ if (selectedItems != null && selectedItems.size() == 1 && !selection.isEmpty() && selectedItems.get(0) == ((IStructuredSelection) selection).getFirstElement()) { itemReSelected = true; } else { itemReSelected = false; } List<IContentData> newSelection = new ArrayList<IContentData>(); for (Iterator iter = sselection.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof IContentData) { IContentData modelData = currentCategory.findById(((IContentData) obj).getId()); if (modelData == null) continue; // set screen context to theme data, will be needed to // creating // bean-widget for elements that don't have screen // element modelData.getAdapter(EditObject.class); newSelection.add(modelData); } else { // select from screen widgets IScreenElement se = JEMUtil.getScreenElement(obj); if (se != null) { // handles colors ICategoryAdapter ca = (ICategoryAdapter) se.getData().getAdapter(ICategoryAdapter.class); IContentData[] peers = ca.getCategorizedPeers(); for (IContentData peer : peers) { newSelection.add(peer); } } } } selectedItems = newSelection; if (!selectedItems.contains(selectionStart)) { selectionStart = null; } // notifies listeners before revealing in the editor because the // statue line may otherwise be changed by other views suppressSelectEvent = true; try { SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection()); for (ISelectionChangedListener l : listeners) { try { l.selectionChanged(event); } catch (Exception e) { e.printStackTrace(); } } } finally { suppressSelectEvent = false; } Control[] controls = container.getChildren(); IContentData last = newSelection.isEmpty() ? null : newSelection.get(newSelection.size() - 1); for (Control ctrl : controls) { ImageLabel label = (ImageLabel) ctrl; if (ctrl.getData() == last) { scrollToVisible(ctrl); } if (newSelection.contains(ctrl.getData())) { label.setSelected(true); } else { label.setSelected(false); } } if (synchronize) { if (!(sselection.size() > 0 && sselection.toArray()[sselection.size() - 1] == Boolean.FALSE)) { suppressSelectEvent = true; try { showSelectionInEditor((IStructuredSelection) selection); } finally { suppressSelectEvent = false; } } } } suppressSelectEvent = true; try { ((IconView) parent).fireSelectionChangeEvent(); } finally { suppressSelectEvent = false; } refreshIconViewActionsState(); }
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
/** * Based on selection of category from the active editor / project Brings * the corresponding editor to top if the selected resource is open. /* w w w .ja v a 2 s . c om*/ */ public void showSelectionInEditor(IStructuredSelection selection) { if (mouseRightClicked) { return; } listenOnSelection = false; try { ISetSelectionTarget target = (ISetSelectionTarget) sourceEditor.getAdapter(ISetSelectionTarget.class); if (target != null) { try { // reveals only when selection has skinnable entities boolean hasValidContents = false; for (Object obj : selection.toArray()) { if (obj instanceof IContentData) { ICategoryAdapter adapter = (ICategoryAdapter) ((IContentData) obj) .getAdapter(ICategoryAdapter.class); if (adapter != null && adapter.getCategorizedPeers().length > 0) { hasValidContents = true; break; } } } if (hasValidContents) { target.selectReveal(selection); } getSite().getActionBars().getStatusLineManager().setMessage(null); getSite().getActionBars().getStatusLineManager().setErrorMessage(null); getSite().getActionBars().getStatusLineManager().update(true); } catch (final RuntimeException e) { if (e.getMessage() != null && e.getMessage().equals(EditorMessages.Editor_Error_NoPreviewScreen)) { // updates the status message asynchronously Display.getCurrent().asyncExec(new Runnable() { public void run() { getSite().getActionBars().getStatusLineManager().setErrorMessage(e.getMessage()); } }); if (itemReSelected && mouseRightClicked) return; else noPreviewAvailableMessageBox(); } else e.printStackTrace(); } } } finally { listenOnSelection = true; } }
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
private void initializeIconViewActions() { IActionBars bars = getSite().getActionBars(); IToolBarManager tbm = bars.getToolBarManager(); tbm.removeAll();/* ww w . j a va2 s . c o m*/ selectAllAction = new IconViewSelectAllAction(this); tbm.add(selectAllAction); tbm.add(new Separator()); copyAction = new CopyImageAction(IconViewPage.this.parent, null); tbm.add(copyAction); pasteAction = new PasteImageAction(IconViewPage.this.parent, null); tbm.add(pasteAction); tbm.add(new Separator()); browseForFileAction = new BrowseForFileAction(IconViewPage.this.parent); tbm.add(browseForFileAction); tbm.add(new Separator()); animateAction = new OpenGraphicsEditorAction(parent, this); animateAction.listenSelection(); animateAction.selectionChanged(null); tbm.add(animateAction); externalToolsDropDown = new IconViewDropDownToolbarAction(this); tbm.add(externalToolsDropDown); tbm.add(new Separator()); clearAction = new ClearImageEditorAction(IconViewPage.this.parent); tbm.add(clearAction); tbm.add(new Separator()); toggleTextAction = new ToggleTextAction(this); IPreferenceStore store = S60WorkspacePlugin.getDefault().getPreferenceStore(); toggleTextAction.setChecked(store.getBoolean(IS60IDEConstants.PREF_SHOW_TITLE_TEXTS)); tbm.add(toggleTextAction); Action toggleSync = new WorkbenchPartAction(null, WorkbenchPartAction.AS_CHECK_BOX) { @Override public void run() { if (synchronize) { synchronize = false; } else { synchronize = true; IStructuredSelection sselection = (IStructuredSelection) getSelection(); if (sselection != null) { if (!(sselection.size() > 0 && sselection.toArray()[sselection.size() - 1] == Boolean.FALSE)) { suppressSelectEvent = true; try { showSelectionInEditor((IStructuredSelection) getSelection()); } finally { suppressSelectEvent = false; } } } } IPreferenceStore store = S60WorkspacePlugin.getDefault().getPreferenceStore(); store.setValue(IS60IDEConstants.PREF_SYNC_WITH_EDITOR, synchronize); } @Override protected boolean calculateEnabled() { return true; } }; ImageDescriptor i1 = UiPlugin.getIconImageDescriptor("resview_toggle_synch.gif", true); toggleSync.setToolTipText(ViewMessages.IconView_toggleSync_tooltip); toggleSync.setImageDescriptor(i1); tbm.add(new Separator()); tbm.add(toggleSync); // Restore last synchronization state boolean syncState = store.getBoolean(IS60IDEConstants.PREF_SYNC_WITH_EDITOR); synchronize = !syncState; toggleSync.setChecked(syncState); toggleSync.run(); /* global action handlers */ setGlobalHandler(bars, new PasteContentDataAction(this, getCommandStack(), null)); setGlobalHandler(bars, new EditImageInSVGEditorAction(this, getCommandStack())); setGlobalHandler(bars, new EditImageInBitmapEditorAction(this, getCommandStack())); setGlobalHandler(bars, new NinePieceConvertAction(this, getCommandStack(), 9)); setGlobalHandler(bars, new NinePieceConvertAction(this, getCommandStack(), 1)); setGlobalHandler(bars, new ElevenPieceConvertAction(this, getCommandStack(), 11)); setGlobalHandler(bars, new ElevenPieceConvertAction(this, getCommandStack(), 1)); /*setGlobalHandler(bars, new ThreePieceConvertAction(this, getCommandStack(), 3)); setGlobalHandler(bars, new ThreePieceConvertAction(this, getCommandStack(), 1));*/ setGlobalHandler(bars, new ConvertAndEditSVGInBitmapEditorAction(this, getCommandStack())); setGlobalHandler(bars, new EditInSystemEditorAction(this, getCommandStack())); setGlobalHandler(bars, new EditMaskAction(this, getCommandStack())); setGlobalHandler(bars, new EditMaskAction2(this, getCommandStack())); setGlobalHandler(bars, new EditSoundInSoundEditorAction(this, getCommandStack())); setGlobalHandler(bars, new BrowseForFileAction(this, getCommandStack())); setGlobalHandler(bars, new SetStretchModeAction(this, getCommandStack(), IMediaConstants.STRETCHMODE_STRETCH)); setGlobalHandler(bars, new SetStretchModeAction(this, getCommandStack(), IMediaConstants.STRETCHMODE_ASPECT)); // undo, redo ActionRegistry ar = (ActionRegistry) sourceEditor.getAdapter(ActionRegistry.class); if (ar != null) { bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), ar.getAction(ActionFactory.UNDO.getId())); bars.setGlobalActionHandler(ActionFactory.REDO.getId(), ar.getAction(ActionFactory.REDO.getId())); } else { IAction action = new SafeUndoAction(parent); bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), action); action = new SafeRedoAction(parent); bars.setGlobalActionHandler(ActionFactory.REDO.getId(), action); } /* add task, add bookmark */ setGlobalHandler(bars, new AddTaskViewAction(parent)); setGlobalHandler(bars, new AddBookmarkViewAction(parent)); // clear element, edit/animate, copy, paste bars.setGlobalActionHandler(OpenGraphicsEditorAction.ID, animateAction); bars.setGlobalActionHandler(ClearImageEditorAction.ID, clearAction); bars.setGlobalActionHandler(PasteImageAction.ID, pasteAction); bars.setGlobalActionHandler(CopyImageAction.ID, copyAction); }
From source file:com.nokia.tools.s60ct.confml.actions.RemoveSequenceItemsAction.java
License:Open Source License
@Override public void initSelectionListener() { selectionListener = new ISelectionListener() { public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { Object[] array = ss.toArray(); for (int i = 0; i < array.length; i++) { Object object = array[i]; if (object instanceof ESimpleSetting || object instanceof EResourceSetting) { ESequenceSettingImpl seqItem = findSeqSetting((EObject) object); if (seqItem != null) { if (widget != null && !widget.isDisposed() && widget.getData() instanceof ESetting) { ESetting setting = ((ESetting) widget //WRONG?!? .getData()); if (seqItem == setting) { setEnabled(true); return; } else { setEnabled(false); return; }//from w ww . j a v a 2 s . c o m } } } } } } // setEnabled(false); } }; // this.addListenerObject(selectionListener); }
From source file:com.nokia.tools.screen.ui.actions.PlayerController.java
License:Open Source License
/** * Tells animators in selection to play. *//* ww w .ja v a 2 s. c o m*/ public void playSelection(IStructuredSelection sel) { if (isPlaying()) { return; } for (Object element : sel.toArray()) { IScreenElement se = JEMUtil.getScreenElement(element); playElement(se); } startPlaying(); notifyPlayStateChanged(PlayState.PLAYING); }
From source file:com.nokia.tools.screen.ui.actions.PlaySelectionAction.java
License:Open Source License
@Override protected boolean calculateEnabled() { PlayerController controller = getController(); if (controller == null) { return false; }/* w w w . j ava2s .c o m*/ if (controller.isPlaying() || controller.isPaused()) { return false; } IStructuredSelection sel = (IStructuredSelection) getSelection(); if (sel == null) { return false; } for (Object element : sel.toArray()) { element = JEMUtil.getScreenElement(element); if (element != null && element instanceof IScreenElement) { IPlayer player = (IPlayer) ((IScreenElement) element).getAdapter(IPlayer.class); if (player != null && player.isPlayable()) { return true; } } } return false; }
From source file:com.nokia.tools.variant.confml.ui.popup.actions.DeleteAction.java
License:Open Source License
public void run(IAction action) { if (!(selection instanceof IStructuredSelection) || selection == null || workbench == null) { return;//from www. ja v a2s . co m } List<EObject> list = new ArrayList<EObject>(); IStructuredSelection iStructuredSelection = (IStructuredSelection) selection; Object[] selected = iStructuredSelection.toArray(); for (Object o : selected) { if (o instanceof EObject) { list.add((EObject) o); } } IResource[] projects = null; Object firstElement = iStructuredSelection.getFirstElement(); // if (firstElement instanceof EConfMLResource) { // // EConfMLResource eConfMLResource = (EConfMLResource) firstElement; // EVariantProject container = (EVariantProject) eConfMLResource // .eContainer(); // // if (container != null) { // // IFile iFile = container.getProject().getFile( // eConfMLResource.getPath()); // try { // projects=iFile.getProject().members(); // } catch (CoreException e) { // // e.printStackTrace(); // } // // } // // } // // DeleteProjectDialog d = new // DeleteProjectDialog(iViewPart.getViewSite() // .getShell(), projects); // d.open(); if (!list.isEmpty()) { MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); mb.setMessage( "Do you want to delete this project(s)? \n(It will be removed from workspace, the action is undone)"); mb.setText("Delete confirmation"); int answer = mb.open(); if (answer == SWT.YES) { DeleteCommand deleteCommand = new DeleteCommand(list); deleteCommand.execute(); iViewPart.getViewSite().getShell().layout(true, true); } } }
From source file:com.nokia.tools.variant.confml.ui.wizards.NewConfigurationWizardPageOne.java
License:Open Source License
public IResource setInitialSelection(IStructuredSelection selection) { Object[] items = selection.toArray(); for (int i = 0; i < items.length; i++) { Object item = items[i];/*from www. j a va 2s .c om*/ if (item instanceof IResource) { IResource res = (IResource) item; if (res instanceof IProject) { return res; } else { if (res.getParent() instanceof IProject) { return res; } else { return res.getProject(); } } } } return null; }