List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.motorolamobility.preflighting.ui.handlers.AnalyzeApkHandler.java
License:Apache License
public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbench workbench = PlatformUI.getWorkbench(); if ((workbench != null) && !workbench.isClosing()) { IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window != null) { ISelection selection = null; if (initialSelection != null) { selection = initialSelection; } else { selection = window.getSelectionService().getSelection(); }/*from www .j a v a 2 s . c om*/ if (selection instanceof IStructuredSelection) { IStructuredSelection sselection = (IStructuredSelection) selection; Iterator<?> it = sselection.iterator(); String sdkPath = AndroidUtils.getSDKPathByPreference(); if (monitor != null) { monitor.setTaskName(PreflightingUiNLS.ApplicationValidation_monitorTaskName); monitor.beginTask(PreflightingUiNLS.ApplicationValidation_monitorTaskName, sselection.size() + 1); monitor.worked(1); } ArrayList<PreFlightJob> jobList = new ArrayList<PreFlightJob>(); boolean isHelpExecution = false; IPreferenceStore preferenceStore = PreflightingUIPlugin.getDefault().getPreferenceStore(); boolean showMessageDialog = true; if (preferenceStore.contains( PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG)) { showMessageDialog = MessageDialogWithToggle.ALWAYS.equals(preferenceStore.getString( PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG)); } if (showMessageDialog && (!preferenceStore.contains(PreflightingUIPlugin.OUTPUT_LIMIT_VALUE)) && preferenceStore.contains(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY) && (!(preferenceStore.getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY)) .equals(PreflightingUIPlugin.DEFAULT_BACKWARD_COMMANDLINE))) { String commandLine = PreflightingUIPlugin.getDefault().getPreferenceStore() .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY); MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Title, NLS.bind(PreflightingUiNLS.AnalyzeApkHandler_BackwardMsg_Message, commandLine), PreflightingUiNLS.AnalyzeApkHandler_Do_Not_Show_Again, false, preferenceStore, PreflightingUIPlugin.SHOW_BACKWARD_DIALOG + PreflightingUIPlugin.TOGGLE_DIALOG); int returnCode = dialog.getReturnCode(); if (returnCode == IDialogConstants.YES_ID) { EclipseUtils.openPreference( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_PAGE); } } String userParamsStr = preferenceStore .getString(PreflightingUIPlugin.COMMAND_LINE_PREFERENCE_KEY); downgradeErrors = preferenceStore .contains(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE) ? preferenceStore .getBoolean(PreflightingUIPlugin.ECLIPSE_PROBLEM_TO_WARNING_VALUE) : true; //we look for a help parameter: -help or -list-checkers //in such case we execute app validator only once, //since all executions will have the same output if (userParamsStr.length() > 0) { String regex = "((?!(\\s+" + "-" + ")).)*"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Pattern pat = Pattern.compile(regex); Matcher matcher = pat.matcher(userParamsStr); while (matcher.find()) { String parameterValues = userParamsStr.substring(matcher.start(), matcher.end()); if (parameterValues.equals("-" //$NON-NLS-1$ + ApplicationParameterInterpreter.PARAM_HELP) || parameterValues.equals( "-" //$NON-NLS-1$ + ApplicationParameterInterpreter.PARAM_LIST_CHECKERS)) { isHelpExecution = true; } } } while (it.hasNext()) { IResource analyzedResource = null; Object resource = it.next(); String path = null; if (resource instanceof IFile) { IFile apkfile = (IFile) resource; analyzedResource = apkfile; if (apkfile.getFileExtension().equals("apk") && apkfile.exists() //$NON-NLS-1$ && apkfile.getLocation().toFile().canRead()) { /* * For each apk, execute all verifications passaing the two needed parameters */ path = apkfile.getLocation().toOSString(); } else { MessageDialog.openError(window.getShell(), PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle, PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage); } } else if (resource instanceof File) { File apkfile = (File) resource; if (apkfile.getName().endsWith(".apk") && apkfile.exists() //$NON-NLS-1$ && apkfile.canRead()) { /* * For each apk, execute all verifications passaing the two needed parameters */ path = apkfile.getAbsolutePath(); } else { MessageDialog.openError(window.getShell(), PreflightingUiNLS.AnalyzeApkHandler_ErrorTitle, PreflightingUiNLS.AnalyzeApkHandler_ApkFileErrorMessage); } enableMarkers = false; } else if (resource instanceof IProject) { IProject project = (IProject) resource; analyzedResource = project; path = project.getLocation().toOSString(); } else if (resource instanceof IAdaptable) { IAdaptable adaptable = (IAdaptable) resource; IProject project = (IProject) adaptable.getAdapter(IProject.class); analyzedResource = project; if (project != null) { path = project.getLocation().toOSString(); } } if (path != null) { PreFlightJob job = new PreFlightJob(path, sdkPath, analyzedResource); jobList.add(job); if (isHelpExecution) { //app validator is executed only once for help commands break; } } } if (enableMarkers) { // Show and activate problems view Runnable showProblemsView = new Runnable() { public void run() { try { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .showView(PROBLEMS_VIEW_ID); } catch (PartInitException e) { PreflightingLogger.error("Error showing problems view."); //$NON-NLS-1$ } } }; Display.getDefault().asyncExec(showProblemsView); } //show console for external apks else { showApkConsole(); } ParentJob parentJob = new ParentJob( PreflightingUiNLS.AnalyzeApkHandler_PreflightingToolNameMessage, jobList); parentJob.setUser(true); parentJob.schedule(); try { if (monitor != null) { monitor.done(); } } catch (Exception e) { //Do nothing } } } } return null; }
From source file:com.muratools.eclipse.MuraToolsAction.java
License:Apache License
public String getTargetDirectory() { String targetPath = ""; String containerPath = ""; if (getSelection() != null && getSelection().isEmpty() == false && getSelection() instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) getSelection(); if (ssel.size() > 1) { return targetPath; }//from www . ja v a 2s . c o m Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container = (IContainer) obj; containerPath = container.getFullPath().toString(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(new Path(containerPath)); if (resource != null) { IPath path = container.getLocation(); targetPath = path.toOSString(); } } } return targetPath; }
From source file:com.muratools.eclipse.MuraToolsWizard.java
License:Apache License
public void refreshContainer() { if (getSelection() != null && getSelection().isEmpty() == false && getSelection() instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) getSelection(); if (ssel.size() > 1) { return; } else {/*from w ww . ja v a 2 s . c o m*/ Object obj = ssel.getFirstElement(); if (obj instanceof IResource) { IContainer container = (IContainer) obj; try { container.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { e.printStackTrace(); } } } } }
From source file:com.netxforge.netxstudio.screens.actions.CompareAction.java
License:Open Source License
@Override protected boolean updateSelection(IStructuredSelection selection) { System.out.println(selection); return selection.size() == 2; }
From source file:com.nextep.designer.beng.ui.handlers.RemoveDeliveryItemHandler.java
License:Open Source License
/** * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) *//*from w ww . j a va2s . c o m*/ @Override public Object execute(ExecutionEvent event) throws ExecutionException { // Retrieving delivery type ISelection sel = HandlerUtil.getCurrentSelection(event); if (sel instanceof IStructuredSelection) { final IStructuredSelection s = (IStructuredSelection) sel; if (s.size() > 1) { final boolean confirmed = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), MessageFormat.format(BengUIMessages.getString("confirmRemoveDeliveryItemTitle"), s.size()), //$NON-NLS-1$ MessageFormat.format(BengUIMessages.getString("confirmRemoveDeliveryItem"), s.size()) //$NON-NLS-1$ ); if (!confirmed) { throw new CancelException("Operation cancelled by user."); } } // Removing all selected items for (Object o : s.toList()) { if (o instanceof IDeliveryItem<?>) { IDeliveryItem<?> i = (IDeliveryItem<?>) o; IDeliveryModule m = i.getParentModule(); m.removeDeliveryItem(i); } } } return null; }
From source file:com.nextep.designer.beng.ui.views.DeliveriesView.java
License:Open Source License
/** * This is a callback that will allow us to create the viewer and initialize it. *//*from w ww . ja v a 2s . c om*/ public void createPartControl(Composite parent) { deliveriesTree = new Tree(parent, SWT.MULTI); treeViewer = new TreeViewer(deliveriesTree); treeViewer.setLabelProvider(new DeliveriesLabelProvider()); treeViewer.setContentProvider(new DeliveriesContentProvider()); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { final IStructuredSelection s = (IStructuredSelection) treeViewer.getSelection(); if (s.size() == 1) { final Object o = s.getFirstElement(); ITypedObject objectToOpen = null; if (o instanceof IDeliveryModule) { objectToOpen = (ITypedObject) o; } else if (o instanceof IDeliveryItem<?>) { Object content = ((IDeliveryItem<?>) o).getContent(); if (content instanceof ITypedObject) { objectToOpen = (ITypedObject) content; } } else if (o instanceof ITypedObject) { objectToOpen = (ITypedObject) o; } if (objectToOpen != null) { UIControllerFactory.getController(objectToOpen).defaultOpen(objectToOpen); } } } }); getSite().setSelectionProvider(treeViewer); // Target of drop operations treeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, this); // We allow dragging from the navigator treeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, this); registerContextMenu(treeViewer); // Registering listener on every root container of this view IWorkspace view = VCSPlugin.getViewService().getCurrentWorkspace(); for (IVersionable<?> v : view.getContents()) { if (v.getType() == IElementType.getInstance(IVersionContainer.TYPE_ID)) { Designer.getListenerService().registerListener(deliveriesTree, v, new IEventListener() { @Override public void handleEvent(ChangeEvent event, IObservable source, Object data) { if (event == ChangeEvent.CHECKOUT || event == ChangeEvent.UPDATES_LOCKED || event == ChangeEvent.UPDATES_UNLOCKED) { refresh(); } } }); } } treeViewer.setInput(view); }
From source file:com.nextep.designer.dbgm.ui.handlers.EditDiagramItemHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty()) { if (sel.size() > WARN_DIALOG_ABOVE) { final boolean confirmed = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), MessageFormat.format(DBGMUIMessages.getString("editDiagramItemWarnCountTitle"), sel.size()), MessageFormat.format(DBGMUIMessages.getString("editDiagramItemWarnCount"), sel.size(), sel.size())); if (!confirmed) { return null; }//from w ww .j a v a 2 s. co m } for (Iterator<?> it = sel.iterator(); it.hasNext();) { final Object o = it.next(); if (o instanceof DiagramItemPart || o instanceof ConnectionEditPart) { Object model = ((GraphicalEditPart) o).getModel(); Object innerModel = model; if (model instanceof IDiagramItem) { innerModel = ((IDiagramItem) model).getItemModel(); } if (innerModel instanceof ITypedObject) { UIControllerFactory.getController(((ITypedObject) innerModel).getType()) .defaultOpen((ITypedObject) innerModel); } } } } } return null; }
From source file:com.nextep.designer.synch.ui.jface.CompareAction.java
License:Open Source License
@Override public boolean isEnabled() { final ISelection sel = selectionProvider.getSelection(); if (!sel.isEmpty()) { final IStructuredSelection selection = (IStructuredSelection) sel; return selection.size() == 1 && selection.getFirstElement() instanceof IComparisonItem; }// w w w . j a v a2 s . co m return false; }
From source file:com.nextep.designer.ui.handlers.EditTypedItemHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection s = HandlerUtil.getCurrentSelection(event); if (s instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) s; if (!sel.isEmpty()) { // Warning before opening too many editors if (sel.size() > WARN_DIALOG_ABOVE) { final boolean confirmed = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), MessageFormat.format(UIMessages.getString("editItemWarnCountTitle"), sel.size()), //$NON-NLS-1$ MessageFormat.format(UIMessages.getString("editItemWarnCount"), sel.size(), sel //$NON-NLS-1$ .size())); if (!confirmed) { return null; }//w w w . j ava2 s. c o m } // If OK, we open everything final Iterator<?> selIt = sel.iterator(); while (selIt.hasNext()) { final Object o = selIt.next(); if ((o instanceof ITypedObject) && !(o instanceof IConnector<?, ?>)) { final ITypedObject t = (ITypedObject) o; UIControllerFactory.getController(t.getType()).defaultOpen(t); } } } } return null; }
From source file:com.nextep.designer.vcs.gef.VersionTreeGUI.java
License:Open Source License
/** * @return the currently selected object in the tree if this GUI has the selectable flag set to * <code>true</code> or the currently edited version otherwise. * @see com.nextep.datadesigner.gui.model.IConnector#getModel() */// w ww. j a v a2 s.c o m @Override public Object getModel() { if (selectable) { if (viewer.getSelection() instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); if (sel.size() > 0 && sel.getFirstElement() instanceof EditPart) { EditPart part = (EditPart) sel.getFirstElement(); if (part.getModel() instanceof IDiagramItem) { return (IVersionInfo) ((IDiagramItem) part.getModel()).getItemModel(); } } } return null; } else { return diagram; } }