Example usage for org.eclipse.jface.viewers IStructuredSelection iterator

List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection iterator.

Prototype

@Override
public Iterator iterator();

Source Link

Document

Returns an iterator over the elements of this selection.

Usage

From source file:com.mobilesorcery.sdk.profiles.ui.DeviceFilterComposite.java

License:Open Source License

protected void removeSelectedFilters() {
    IStructuredSelection selection = (IStructuredSelection) filterTable.getSelection();
    for (Iterator selected = selection.iterator(); selected.hasNext();) {
        filter.removeFilter((IDeviceFilter) selected.next());
        updateUI(true);//  w w w.  j  a v  a  2  s  . com
    }
}

From source file:com.motorola.studio.android.command.CleanProjects.java

License:Apache License

public Object execute(ExecutionEvent event) throws ExecutionException {

    // Retrieve the selection used in the command
    IWorkbench workbench = PlatformUI.getWorkbench();
    if ((workbench != null) && !workbench.isClosing()) {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window != null) {
            ISelection selection = window.getSelectionService().getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection sselection = (IStructuredSelection) selection;
                Iterator<?> it = sselection.iterator();

                // Construct a list of valid projects to be cleaned
                List<IProject> projectList = new ArrayList<IProject>(sselection.size());

                while (it.hasNext()) {
                    Object resource = it.next();

                    // Check if the selected item is a project
                    if (resource instanceof IProject) {
                        projectList.add(((IProject) resource));
                    } else if (resource instanceof IAdaptable) {
                        IAdaptable adaptable = (IAdaptable) resource;
                        projectList.add((IProject) adaptable.getAdapter(IProject.class));

                    }/*from  w  w  w  .j  av  a 2 s  . co  m*/

                }

                // Instantiate the clean job and schedule it.
                if (projectList.size() > 0) {
                    CleanProjectsJob job = new CleanProjectsJob(projectList);
                    job.schedule();
                }

            }
        }
    }
    return null;
}

From source file:com.motorola.studio.android.packaging.ui.export.PackageExportWizardArea.java

License:Apache License

/**
 * This method normalize the selection only to contain projects and
 * descriptors/*from w w  w  . j a va2s  .c  om*/
 * 
 * @return
 * @throws CoreException
 */
@SuppressWarnings("unchecked")
private IStructuredSelection normalizeSelection(IStructuredSelection selection) {
    ArrayList<Object> normalized = new ArrayList<Object>();
    Iterator<Object> iterator = selection.iterator();
    while (iterator.hasNext()) {
        Object item = iterator.next();
        IResource resource = null;
        if (item instanceof IResource) {
            resource = (IResource) item;
        } else if (item instanceof IAdaptable) {
            try {
                resource = (IResource) ((IAdaptable) item).getAdapter(IResource.class);
            } catch (Exception e) {
                StudioLogger.warn("Error retrieving projects.");
            }
        }
        if (resource != null) {
            IProject project = resource.getProject();
            if (!normalized.contains(project)) {
                normalized.add(project);
            }
        }

    }
    return new StructuredSelection(normalized);
}

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();
            }/*w  w  w .  j a v  a2s .co  m*/

            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.netxforge.netxstudio.screens.f3.charts.ChartScreen.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//  ww  w .  jav a2  s.c  om
public boolean handleShowIn(ShowInContext context) {

    ISelection selection = context.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
        IStructuredSelection ss = (StructuredSelection) selection;
        final Object[] objects = Lists.newArrayList(ss.iterator()).toArray();
        if (context.getInput() instanceof ChartMergeInput) {
            internalInjectData(MODE_MERGE_CHART, objects);
            return true;
        } else if (context.getInput() instanceof ChartInput) {
            internalInjectData(MODE_REINIT_MODEL, objects);
            return true;
        } else if (context.getInput() instanceof ChartMergeInput) {

        }
    }

    return false;
}

From source file:com.netxforge.netxstudio.screens.parts.ChartScreenViewer.java

License:Open Source License

@SuppressWarnings("unchecked")
protected void processSelection(ISelection selection) {
    if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
        IStructuredSelection ss = (StructuredSelection) selection;

        if (!chartScreen.isDisposed()) {// Closing a view will dispose it!
            chartScreen.injectData(Lists.newArrayList(ss.iterator()).toArray());
        }//  w  w  w. j  a v a2 s  .com
    }
}

From source file:com.nextep.designer.beng.ui.views.DeliveriesView.java

License:Open Source License

@Override
public void dragOver(DropTargetEvent e) {
    for (int i = 0; i < e.dataTypes.length; i++) {
        final ISelection s = LocalSelectionTransfer.getTransfer().getSelection();
        if (s instanceof IStructuredSelection && !s.isEmpty()) {
            final IStructuredSelection sel = (IStructuredSelection) s;
            // Only accepting tables or containers
            final Iterator<?> selIt = sel.iterator();
            while (selIt.hasNext()) {
                Object elt = selIt.next();
                // If not a table and not a container we deny the drop action
                if (!(elt instanceof ISQLScript)
                        && (!(elt instanceof IDeliveryItem) || (elt instanceof IDeliveryModule))) {
                    return;
                }//from   w w w .  jav  a2s.  c  o m
            }
            // Only accepting the drop to delivery types
            TreeItem item = (TreeItem) e.item;
            if (item != null && item.getData() instanceof DeliveryTypeItem) {
                e.currentDataType = e.dataTypes[i];
                e.detail = DND.DROP_LINK;
            } else {
                e.detail = DND.DROP_NONE;
            }
        }
    }
}

From source file:com.nextep.designer.beng.ui.views.DeliveriesView.java

License:Open Source License

@Override
public void drop(DropTargetEvent e) {

    if (e.data instanceof IStructuredSelection) {
        final IDeliveryService deliveryService = BengPlugin.getService(IDeliveryService.class);
        final IStructuredSelection s = (IStructuredSelection) e.data;
        final Iterator<?> selIt = s.iterator();
        while (selIt.hasNext()) {

            Object draggedObj = selIt.next();
            if (draggedObj instanceof ISQLScript
                    || (draggedObj instanceof IDeliveryItem && !(draggedObj instanceof IDeliveryModule))) {

                TreeItem i = (TreeItem) e.item;
                if (i != null && i.getData() instanceof DeliveryTypeItem) {
                    final DeliveryTypeItem typeItem = (DeliveryTypeItem) i.getData();
                    final DeliveryType type = typeItem.getType();
                    final IDeliveryModule module = typeItem.getModule();

                    IDeliveryItem<?> addedItem = null;
                    if (draggedObj instanceof VersionedSQLScript) {
                        final VersionedSQLScript vs = (VersionedSQLScript) draggedObj;
                        // Dropping a script on a JDBC module require specific processing
                        // as this script should be executed for all vendors. We do this
                        // by setting a null vendor, interpreted by the installer as "any"
                        // vendor
                        DBVendor vendor = vs.getContainer().getDBVendor();
                        if (vendor == DBVendor.JDBC) {
                            vendor = null;
                        }/*from  www .  ja va 2 s  .c  om*/
                        addedItem = deliveryService.createDeliveryScript(type, vs.getSqlScript());
                        addedItem.setDBVendor(vendor);
                        module.addDeliveryItem(addedItem);
                    } else if (draggedObj instanceof ISQLScript) {
                        // Dropping a script on a JDBC module require specific processing
                        // as this script should be executed for all vendors. We do this
                        // by setting a null vendor, interpreted by the installer as "any"
                        // vendor
                        DBVendor vendor = DBGMHelper.getCurrentVendor();
                        if (vendor == DBVendor.JDBC) {
                            vendor = null;
                        }
                        addedItem = deliveryService.createDeliveryScript(type, (ISQLScript) draggedObj);
                        addedItem.setDBVendor(vendor);
                        module.addDeliveryItem(addedItem);
                    } else if (draggedObj instanceof IDeliveryItem) {
                        final IDeliveryItem<?> dlv = (IDeliveryItem<?>) draggedObj;
                        module.removeDeliveryItem(dlv);
                        dlv.setDeliveryType(type);
                        module.addDeliveryItem(dlv);
                        addedItem = dlv;
                    }
                    treeViewer.expandToLevel(addedItem, 1);
                } else {
                    log.error("Unable to drop this SQL script here, please target a valid delivery container."); //$NON-NLS-1$
                }
            } else {
                log.error("Deliveries only accept SQL scripts drag / drop sources."); //$NON-NLS-1$
            }
        }
    }
}

From source file:com.nextep.designer.dbgm.gef.DiagramSelectionDropTargetListener.java

License:Open Source License

@Override
public void dragOver(DropTargetEvent e) {
    for (int i = 0; i < e.dataTypes.length; i++) {
        final ISelection s = LocalSelectionTransfer.getTransfer().getSelection();
        if (s instanceof IStructuredSelection && !s.isEmpty()) {
            final IStructuredSelection sel = (IStructuredSelection) s;
            // Only accepting tables or containers
            final Iterator<?> selIt = sel.iterator();
            while (selIt.hasNext()) {
                Object elt = selIt.next();
                // If not a table and not a container we deny the drop action
                if (!(elt instanceof IBasicTable) && !(elt instanceof IVersionContainer)) {
                    return;
                }//from w  ww.j a v  a 2s  .  c o  m
            }
            // We fall here when we got compatible elements (tables and/or containers)
            e.currentDataType = e.dataTypes[i];
            e.detail = DND.DROP_MOVE;
        }
    }
}

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;
                }/*  w  w  w. j  av 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;
}