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

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

Introduction

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

Prototype

@Override
    public Iterator iterator() 

Source Link

Usage

From source file:ac.soton.eventb.classdiagrams.diagram.sheet.ClassdiagramsPropertySection.java

License:Open Source License

/**
 * @generated//from   w w  w.j  a v  a2 s.co  m
 */
public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList transformedSelection = new ArrayList(structuredSelection.size());
    for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
        Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:ar.com.tadp.prolog.core.actions.AddPrologCapabilitiesToProjectAction.java

License:Open Source License

@Override
public void run(final IAction action) {
    final PluginAction pAction = (PluginAction) action;
    final StructuredSelection selection = (StructuredSelection) pAction.getSelection();

    for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        try {// w ww.j  a v a  2 s .co  m
            final IProject selectedProject = (IProject) iterator.next();
            if (selectedProject.isOpen()) {
                ResourceUtil.addPrologNature(selectedProject);
            }
        } catch (final Exception e) {
        }
    }
}

From source file:ar.com.tadp.prolog.core.actions.RemovePrologCapabilitiesToProjectAction.java

License:Open Source License

@Override
public void run(final IAction action) {
    final PluginAction pAction = (PluginAction) action;
    final StructuredSelection selection = (StructuredSelection) pAction.getSelection();

    for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        try {//from   w  w w. j  a va2  s  .c  o  m
            final IProject selectedProject = (IProject) iterator.next();
            if (selectedProject.isOpen()) {
                ResourceUtil.removePrologNature(selectedProject);
            }
        } catch (final Exception e) {
        }
    }
}

From source file:bndtools.MakeBundle.java

License:Open Source License

@SuppressWarnings("unchecked")
IFile[] getLocations(ISelection selection) {
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        IFile[] result = new IFile[ss.size()];
        int n = 0;
        for (Iterator<IFile> i = ss.iterator(); i.hasNext();) {
            result[n++] = i.next();//from ww  w.j  a  v a  2s .  c om
        }
        return result;
    }
    return null;
}

From source file:bndtools.release.ReleaseAction.java

License:Open Source License

static IFile[] getLocations(ISelection selection) {
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        IFile[] result = new IFile[ss.size()];
        int n = 0;
        for (@SuppressWarnings("unchecked")
        Iterator<IFile> i = ss.iterator(); i.hasNext();) {
            result[n++] = i.next();/*from  w ww  .  jav  a 2  s.  c  o m*/
        }
        return result;
    }
    return null;
}

From source file:bndtools.release.WorkspaceReleaseAction.java

License:Open Source License

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 *//*w  ww.  jav a2s.  c  o  m*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
    projects = Collections.emptySet();
    if (selection != null && (selection instanceof StructuredSelection)) {
        StructuredSelection ss = (StructuredSelection) selection;
        projects = new HashSet<IProject>();
        for (Iterator<?> itr = ss.iterator(); itr.hasNext();) {
            Object selected = itr.next();
            if (selected instanceof IProject) {
                projects.add((IProject) selected);
            } else if (selected instanceof IWorkingSet) {
                IWorkingSet workingSet = (IWorkingSet) selected;
                for (IAdaptable adaptable : workingSet.getElements()) {
                    IProject project = (IProject) adaptable.getAdapter(IProject.class);
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            } else if (selected instanceof IFile) {
                IFile bndFile = (IFile) selected;
                if (bndFile.getName().endsWith(Constants.DEFAULT_BND_EXTENSION)) {
                    if (!projects.contains(bndFile.getProject()))
                        projects.add(bndFile.getProject());
                }
            }
        }
    }
}

From source file:br.unb.cic.rtgoretoprism.action.AbstractCodeGeneractionAction.java

License:Open Source License

/**
 * Allow the selection only if a set of (sub)Actor has been chosen
 * //  w  ww.  j a  v  a2  s  .c  o m
 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged(IAction action, ISelection selection) {
    //at first disable the action
    action.setEnabled(false);

    //if( shell == null )
    //   return;

    //assure no actor is selected
    selectedActors.clear();
    selectedGoals.clear();

    //then verify if it is necessary to enable it
    if (!(selection instanceof StructuredSelection))
        return;

    //current selection
    StructuredSelection ss = (StructuredSelection) selection;

    Iterator it = ss.iterator();

    while (it.hasNext()) {
        //current selected element
        Object selected = it.next();

        //we expect only an MD_ActorUIEditPart type
        if ((selected instanceof MD_IntentionalUIEditPart)) {
            MD_IntentionalUIEditPart currEP = (MD_IntentionalUIEditPart) selected;
            MD_IntentionalUI currActorUI = (MD_IntentionalUI) currEP.getModel();
            //current selected Actor model objectMD_ActorUIEditPart
            if (currActorUI.getSingleCore() instanceof FHardGoal) {
                FHardGoal currGoal = (FHardGoal) currActorUI.getSingleCore();
                //add it to the set
                selectedGoals.add(currGoal);
                selectedActors.add(currGoal.getActor());
                action.setEnabled(true);
            }
        } else {
            //we expect only an MD_ActorUIEditPart type
            if (!(selected instanceof MD_ActorUIEditPart))
                return;

            MD_ActorUIEditPart currEP = (MD_ActorUIEditPart) selected;
            MD_ActorUI currActorUI = (MD_ActorUI) currEP.getModel();
            //current selected Actor model objectMD_ActorUIEditPart
            Actor currActor = (Actor) currActorUI.getSingleCore();

            //mm: Commented to allow code generation for all agents
            ////we accept only system one
            //if( !currActor.isIsSystem() )
            //   return;

            //add it to the set
            selectedActors.add(currActor);

            //get all owned subsystems, if any
            List subSystems = currActor.getSubsystems();
            //add the to the set too
            for (Object a : subSystems)
                selectedActors.add((Actor) a);
        }

        //if here, we are ok so enable the action back
        action.setEnabled(true);
    }
}

From source file:ch.elexis.extdoc.views.ExterneDokumente.java

License:Open Source License

private void makeActions() {
    sendMailAction = new Action() {
        public void run() {
            Object element = null;
            List<File> attachements = new ArrayList<>();
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (selection != null && !selection.isEmpty()) {
                Iterator<?> iterator = selection.iterator();
                while (iterator.hasNext()) {
                    element = iterator.next();
                    if (element instanceof File) {
                        attachements.add((File) element);
                    }//  w  w  w.  j a  va 2 s .  c om
                }
            }
            if (actPatient != null) {
                String inhalt = Email.getEmailPreface(actPatient);
                inhalt += "\n\n\nMedikation: \n" + actPatient.getMedikation();
                inhalt += "\nAlle Konsultationen\n" + Email.getAllKonsultations(actPatient) + "\n\n";
                Email.openMailApplication("", // No default to address
                        null, inhalt, attachements);
            }
        }
    };
    sendMailAction.setText(Messages.ExterneDokumente_sendEmail);
    sendMailAction.setImageDescriptor(Images.IMG_MAIL.getImageDescriptor());
    sendMailAction.setToolTipText(Messages.ExterneDokumente_sendEmailTip);
    openFolderAction = new Action() {
        public void run() {
            List<File> directories = ListFiles.getDirectoriesForActPatient(actPatient);
            if (directories.size() == 0) {
                if (actPatient != null) {
                    logger.info("No active directories for " + actPatient.getPersonalia());
                }
                return;
            }
            for (File directory : directories) {
                logger.info("will launch folder: " + directory.toString());
                if (Program.launch("file://" + directory.toString()) == false) {
                    logger.info("Could not open directory " + directory.toString());
                }
            }
        }
    };
    openFolderAction.setText(Messages.ExterneDokumente_openFolder);
    openFolderAction
            .setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin("org.iatrix", "rsc/folder.png"));
    openFolderAction.setToolTipText(Messages.ExterneDokumente_openFolderTip);

    openAction = new Action() {
        public void run() {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (selection != null) {
                Object element = selection.getFirstElement();
                if (element instanceof File) {
                    File file = (File) element;
                    String path = file.getAbsolutePath();
                    Program.launch(path);
                }
            }
        }
    };
    openAction.setText(Messages.ExterneDokumente_open);
    openAction.setToolTipText(Messages.ExterneDokumente_OpenFileTip);
    openAction.setImageDescriptor(Images.IMG_DOCUMENT_TEXT.getImageDescriptor());
    doubleClickAction = new Action() {
        @Override
        public void run() {
            openAction.run();
        }
    };

    editAction = new Action() {
        @Override
        public void run() {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (selection != null) {
                Object element = selection.getFirstElement();
                if (element instanceof File) {
                    openFileEditorDialog((File) element);
                }
            }
        }
    };
    editAction.setText(Messages.ExterneDokumente_propeties);
    editAction.setToolTipText(Messages.ExterneDokumente_rename_or_change_date);
    editAction.setActionDefinitionId("ch.elexis.extdoc.commands.edit_properties");
    editAction.setImageDescriptor(Images.IMG_EDIT.getImageDescriptor());
    GlobalActions.registerActionHandler(this, editAction);

    deleteAction = new Action() {
        public void run() {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (selection != null) {
                Object element = selection.getFirstElement();
                if (element instanceof File) {
                    File file = (File) element;

                    if (SWTHelper.askYesNo(Messages.ExterneDokumente_delete_doc,
                            Messages.ExterneDokumente_shold_doc_be_delted + file.getName())) {
                        logger.info("Datei Lschen: " + file.getAbsolutePath()); //$NON-NLS-1$
                        file.delete();
                        refresh();
                    }
                }
            }
        }
    };
    deleteAction.setText(Messages.ExterneDokumente_delete);
    deleteAction.setToolTipText(Messages.ExterneDokumente_delete_files);
    deleteAction.setActionDefinitionId(GlobalActions.DELETE_COMMAND);
    GlobalActions.registerActionHandler(this, deleteAction);

    renameAction = new Action() {
        public void run() {
            StructuredSelection selection = (StructuredSelection) viewer.getSelection();
            if (selection != null) {
                Object element = selection.getFirstElement();
                if (element instanceof File) {
                    openFileEditorDialog((File) element);
                }
            }
        }
    };
    renameAction.setText(Messages.ExterneDokumente_renaming_file);
    renameAction.setToolTipText(Messages.ExterneDokumente_renaming_file);
    renameAction.setActionDefinitionId("ch.elexis.extdoc.commands.rename");
    GlobalActions.registerActionHandler(this, renameAction);

    verifyAction = new Action() {
        public void run() {
            new VerifierDialog(getViewSite().getShell(), actPatient).open();
            // files may have been renamed
            refresh();
        }
    };
    verifyAction.setText(Messages.ExterneDokumente_verify_files);
    verifyAction.setToolTipText(Messages.ExterneDokumente_verify_files_Belong_to_patient);
    moveIntoSubDirsActions = new ch.elexis.extdoc.dialogs.MoveIntoSubDirsDialog();
    moveIntoSubDirsActions.setText(Messages.ExterneDokumente_move_into_subdir);
    moveIntoSubDirsActions.setToolTipText(Messages.ExterneDokumente_move_into_subdir_tooltip);
}

From source file:ch.medshare.elexis.directories.views.WeisseSeitenSearchView.java

License:Open Source License

@SuppressWarnings("unchecked")
private void openPatientenDialog() {
    final StructuredSelection selection = (StructuredSelection) kontakteTableViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<KontaktEntry> iterator = selection.iterator();
        while (iterator.hasNext()) {
            final KontaktEntry selectedKontakt = iterator.next();
            searchForm.openPatientenDialog(selectedKontakt);
        }//from ww w .  ja va 2  s  . co  m
    }
}

From source file:ch.medshare.elexis.directories.views.WeisseSeitenSearchView.java

License:Open Source License

@SuppressWarnings("unchecked")
private void openKontaktDialog() {
    final StructuredSelection selection = (StructuredSelection) kontakteTableViewer.getSelection();
    if (!selection.isEmpty()) {
        Iterator<KontaktEntry> iterator = selection.iterator();
        while (iterator.hasNext()) {
            final KontaktEntry selectedKontakt = iterator.next();
            searchForm.openKontaktDialog(selectedKontakt);
        }/*from   www . j  a va2 s . c om*/
    }
}