List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java
License:Open Source License
private void remove() { IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection(); Iterator<?> elements = selection.iterator(); while (elements.hasNext()) { TemplatePersistenceData data = (TemplatePersistenceData) ((PathNode) elements.next()).getData(); getTemplateStore().delete(data); }/*from w w w. j av a 2 s. com*/ iTreeViewer.refresh(); }
From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java
License:Open Source License
private void revert() { IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection(); Iterator<?> elements = selection.iterator(); while (elements.hasNext()) { TemplatePersistenceData data = (TemplatePersistenceData) ((PathNode) elements.next()).getData(); data.revert();// w w w. j av a 2 s . c om } selectionChanged(); iTreeViewer.refresh(); }
From source file:com.nokia.testfw.codegen.ui.preferences.TESTFWTemplatePreferencePage.java
License:Open Source License
/** * Updates the buttons./*w ww. ja v a 2 s .c o m*/ */ protected void updateButtons() { IStructuredSelection selection = (IStructuredSelection) iTreeViewer.getSelection(); int selectionCount = selection.size(); boolean canRestore = getTemplateStore().getTemplateData(true).length != getTemplateStore() .getTemplateData(false).length; boolean canRevert = false; TemplatePersistenceData data = null; for (Iterator<?> it = selection.iterator(); it.hasNext();) { data = (TemplatePersistenceData) ((PathNode) it.next()).getData(); if (data != null && data.isModified()) { canRevert = true; break; } } iEditButton.setEnabled(selectionCount == 1 && data != null); iExportButton.setEnabled(selectionCount > 0); iRemoveButton.setEnabled(selectionCount > 0); iRestoreButton.setEnabled(canRestore); iRevertButton.setEnabled(canRevert); }
From source file:com.nokia.tools.media.utils.editor.AbstractMediaEditorPart.java
License:Open Source License
/** * fill's contents of anim. row controls with adequate composite for * selected row//from w ww .j a v a 2 s . co m * * @param sel */ protected void refreshAnimationControls(final IStructuredSelection sel, final boolean onProperty) { if (sel != null) _lastSelection = sel; if (animationControls == null) { return; } IAnimatedImage anim = null; ILayerEffect eff = null; if (sel != null) { Iterator it = sel.iterator(); while (it.hasNext()) { Object o = it.next(); if (o instanceof TimeLineRow) { // found Object source = ((TimeLineRow) o).getSource(); if (source instanceof ILayerEffect) { eff = (ILayerEffect) source; break; } else if (source instanceof IAnimatedImage) { anim = (IAnimatedImage) source; break; } } } } if (eff == null && anim == null) { clearComposite(animationControls); } else if (anim != null) { final IAnimatedImage selectedAnim = anim; Display.getDefault().asyncExec(new Runnable() { public void run() { if (animationControls.getChildren() != null) if (animationControls.getChildren().length > 0) { Composite cont = (Composite) animationControls.getChildren()[0]; if (cont.getChildren().length > 0) { Control animCont = cont.getChildren()[0]; if (animCont instanceof FrameAnimationContainer) { if (((FrameAnimationContainer) animCont).getImage() == selectedAnim) { return; // selection didn't change } } } } // clear clearComposite(animationControls); // update anim controls composite _updateAnimControlCompositeForAnimatedImage(selectedAnim, animationControls); animationControls.layout(); animationControls.redraw(); } }); } }
From source file:com.nokia.tools.s60.editor.actions.AbstractAction.java
License:Open Source License
@Override public void run() { selection = new StructuredSelection( ((IStructuredSelection) getSelectionProvider().getSelection()).toArray()); /* fix for selection for TreeNode's */ selection = preprocessSelection(selection); final IStructuredSelection sel = (IStructuredSelection) getSelection(); if (!multipleSelection && sel.size() == 1) { doRun(sel.getFirstElement());// w w w .j av a 2s. com } else if (multipleSelection && sel.size() > 0) { Iterator it = sel.iterator(); List<Object> elements = new ArrayList<Object>(); while (it.hasNext()) elements.add(it.next()); if (this instanceof AbstractMultipleSelectionAction) { ((AbstractMultipleSelectionAction) this).doRun(elements); } else { doRun(elements); } } }
From source file:com.nokia.tools.s60.editor.actions.AbstractAction.java
License:Open Source License
/** * replaces items in selection, so that there are object user friendly for * later processing, i.e. replaces TreeNode's with it's data object. * // w w w .j ava 2 s .co m * @param s * @return */ private IStructuredSelection preprocessSelection(IStructuredSelection s) { if (s != null && s.size() > 0) { List<Object> tmp = new ArrayList<Object>(); Iterator it = s.iterator(); while (it.hasNext()) { Object obj = it.next(); if (obj.getClass().getName().indexOf("TreeNode") > 0) { try { Object data = obj.getClass().getMethod("getContent", (Class[]) null).invoke(obj, (Object[]) null); if (data instanceof IContentData) { Set childrens = (Set) obj.getClass().getMethod("getChildren", (Class[]) null) .invoke(obj, (Object[]) null); if (childrens.size() == 1) { data = childrens.toArray()[0]; data = data.getClass().getMethod("getContent", (Class[]) null).invoke(data, (Object[]) null); if (data instanceof IScreenElement) obj = ((IScreenElement) data).getData(); } } else if (data instanceof IScreenElement) { obj = ((IScreenElement) data).getData(); } } catch (Exception ex) { ex.printStackTrace(); } } tmp.add(obj); } return new StructuredSelection(tmp); } return s; }
From source file:com.nokia.tools.s60.editor.actions.AbstractAction.java
License:Open Source License
@Override protected boolean calculateEnabled() { layerCache.enable();//from ww w . j ava 2s .c o m try { if (getSelectionProvider() == null) { return false; } if (!(getSelectionProvider().getSelection() instanceof IStructuredSelection)) return false; // store original selection selection = (IStructuredSelection) getSelectionProvider().getSelection(); selection = preprocessSelection(selection); final IStructuredSelection sel = (IStructuredSelection) getSelection(); if (sel.size() == 1) { return doCalculateEnabled(sel.getFirstElement(), 0); } else if (multipleSelection && sel.size() > 1) { Iterator it = sel.iterator(); int index = 0; while (it.hasNext()) { Object next = it.next(); if (next != null) { boolean enabled = doCalculateEnabled(next, index++); if (!enabled && multipleSelectionEnablement == MultipleSelectionEnablementEnum.ALL) { return false; } else if (enabled && multipleSelectionEnablement == MultipleSelectionEnablementEnum.ONE) { return true; } } } if (multipleSelectionEnablement == MultipleSelectionEnablementEnum.ONE) { return false; } else { return true; } } return false; } finally { layerCache.disable(); } }
From source file:com.nokia.tools.s60.editor.actions.ClearImageEditorAction.java
License:Open Source License
public void run() { IStructuredSelection selection = this.selection; boolean multi = false; List<Command> multiCmdList = null; if (selection.size() > 1) { multi = true;//from w w w .j av a2s. c om multiCmdList = new ArrayList<Command>(); } IContentData data = null; EditPart editPart = null; // partEntity - for 9-piece elements IImage partEntity = null; Iterator els = selection.iterator(); while (els.hasNext()) { Object obj = els.next(); if (obj instanceof IContentData) { data = (IContentData) obj; } else if (obj instanceof EditPart) { IScreenElement screenElement = getScreenElement((EditPart) obj); if (screenElement == null) { continue; } data = screenElement.getData(); } else { boolean isPartElement = false; if (obj instanceof Object[]) { IImage selectedImg = null; if (((Object[]) obj)[1] instanceof IImage) selectedImg = (IImage) ((Object[]) obj)[1]; else if (((Object[]) obj)[1] instanceof ILayer) { selectedImg = ((ILayer) ((Object[]) obj)[1]).getParent(); } if (selectedImg != null) { // EditPart or IContentData is in selection if (selectedImg.isPart()) { isPartElement = true; partEntity = selectedImg; } if (((Object[]) obj)[2] instanceof EditPart) { editPart = (EditPart) ((Object[]) obj)[2]; IScreenElement screenElement = getScreenElement(editPart); data = screenElement.getData(); } else if (((Object[]) obj)[2] instanceof IContentData) { editPart = null; data = (IContentData) ((Object[]) obj)[2]; } } } if (isPartElement && partEntity == null) { continue; } } if (data != null) { ISkinnableEntityAdapter skAdapter = (ISkinnableEntityAdapter) data .getAdapter(ISkinnableEntityAdapter.class); IMediaFileAdapter fileAdapter = (IMediaFileAdapter) data.getAdapter(IMediaFileAdapter.class); if (skAdapter != null && (skAdapter.isSkinned())) { ForwardUndoCompoundCommand command = new ForwardUndoCompoundCommand( com.nokia.tools.s60.editor.commands.Messages.Clear_Label); command.add(skAdapter.getApplyBitmapPropertiesCommand(new BitmapProperties())); IColorAdapter ca = (IColorAdapter) data.getAdapter(IColorAdapter.class); if (ca != null) { // extract color and set it command.add(ca.getApplyColorCommand(ca.getColourFromGraphics(null), false)); } if (fileAdapter != null) { command.add(fileAdapter.getApplyDurationCommand(fileAdapter.getDurationFromGraphics())); command.add(fileAdapter.getApplyMediaFileCommand(null)); } ClearImageCommand cmd = null; //Set fireContentChanged argument to true if it is the last in the selection so that //required views gets refresh. if (els.hasNext()) { cmd = new ClearImageCommand(data, editPart, partEntity, false); } else { //last element in the selection cmd = new ClearImageCommand(data, editPart, partEntity, true); } command.add(cmd); if (multi) { multiCmdList.add(command); } else { execute(command, getEditPart(obj)); } IEditorPart activeEd = EclipseUtils.getActiveSafeEditor(); if (activeEd instanceof Series60EditorPart) { IFile original = ((FileEditorInput) activeEd.getEditorInput()).getFile(); ColorGroups grps = ColorGroupsStore.getColorGroupsForProject(original.getProject()); for (ColorGroup grp : grps.getGroups()) { if (grp.containsItemWithIdAndLayerName(data.getId(), null)) { //grp.removeItemFromGroup(data.getId(), null); RemoveFromGroupCommand removeFromGroupCommand = new RemoveFromGroupCommand( data.getId(), null, grp, grps); execute(removeFromGroupCommand, getEditPart(obj)); break; } } } } } // Support for clearing of audio changed/skinned elements if (data != null) { ISkinnableContentDataAdapter isca = (ISkinnableContentDataAdapter) data .getAdapter(ISkinnableContentDataAdapter.class); if (isca != null) { Command clearSkinnedElementCommand = isca.getClearSkinnedElementCommand(); if (multi) { Command subCmdClear = clearSkinnedElementCommand; multiCmdList.add(subCmdClear); } else { execute(clearSkinnedElementCommand, editPart); } } } } if (multi && multiCmdList.size() > 0) { IRunnableWithProgress runnable = createRunnable(multiCmdList, editPart); // ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog( // Display.getCurrent().getActiveShell()); try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, false, runnable); // progressMonitorDialog.run(true, false, runnable); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:com.nokia.tools.s60.editor.GraphicsEditorPart.java
License:Open Source License
@Override public void selectionChanged(IStructuredSelection selection) { super.selectionChanged(selection); Iterator it = selection.iterator(); while (it.hasNext()) { Object o = it.next();/* ww w . j a va 2 s . co m*/ if (o instanceof ITimeLineRow) { // synchronize selection synchronizeSelection((ITimeLineRow) o); } } }
From source file:com.nokia.tools.s60.editor.Series60ContentOutlinePage.java
License:Open Source License
/** * Initializes the category view.//from w ww. j ava2s . c o m */ protected void initializeCategoryView() { if (!categoryInitialized) { categoryInitialized = true; stackChanged(null); getSite().setSelectionProvider(new ISelectionProvider() { public void addSelectionChangedListener(ISelectionChangedListener listener) { } public ISelection getSelection() { IStructuredSelection selection = (IStructuredSelection) categoryViewer.getSelection(); 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) { newSelection.add(screenElem.getWidget()); } } return new StructuredSelection(newSelection); } public void removeSelectionChangedListener(ISelectionChangedListener listener) { } public void setSelection(ISelection selection) { } }); } }