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

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

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.aptana.projects.internal.wizards.ProjectTemplateSelectionPage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    StructuredSelection selection = (StructuredSelection) event.getSelection();
    setSelectedTemplate(selection.isEmpty() ? null : (IProjectTemplate) selection.getFirstElement());
}

From source file:com.aptana.ui.properties.ProjectNaturesPage.java

License:Open Source License

/**
 * Updates the buttons' enablement.//from w  ww. j  a  v a 2 s  . c o m
 */
private void updateButtons() {
    StructuredSelection selection = (StructuredSelection) fTableViewer.getSelection();
    fMakePrimaryButton.setEnabled(!selection.isEmpty() && !isPrimary(selection.getFirstElement()));
}

From source file:com.centurylink.mdw.plugin.designer.properties.ProcessVersionsSection.java

License:Apache License

private Menu createContextMenu(Shell shell) {
    Menu menu = new Menu(shell, SWT.POP_UP);

    final StructuredSelection selection = (StructuredSelection) tableEditor.getTableViewer().getSelection();
    if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowProcess) {
        final WorkflowProcess processVer = (WorkflowProcess) selection.getFirstElement();

        MenuItem openItem = new MenuItem(menu, SWT.PUSH);
        openItem.setText("Open");
        ImageDescriptor openImageDesc = MdwPlugin.getImageDescriptor("icons/process.gif");
        openItem.setImage(openImageDesc.createImage());
        openItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                openProcess(processVer);
            }/*  w w  w . j  av  a2  s.  c  om*/
        });
    }
    // delete
    if (!selection.isEmpty() && !process.getProject().isProduction()
            && process.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)
            && (selection.size() == 1 && ((WorkflowProcess) selection.getFirstElement()).isLatest())
            || MdwPlugin.getSettings().isAllowDeleteArchivedProcesses()) {
        MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
        deleteItem.setText("Delete...");
        ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
        deleteItem.setImage(deleteImageDesc.createImage());
        deleteItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (selection.size() >= 1 && selection.getFirstElement() instanceof WorkflowProcess) {
                    WorkflowProcess[] processVers = new WorkflowProcess[selection.size()];
                    int idx = 0;
                    for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
                        processVers[idx] = (WorkflowProcess) iter.next();
                        idx++;
                    }
                    WorkflowElementActionHandler actionHandler = new WorkflowElementActionHandler();
                    actionHandler.delete(processVers);
                    boolean removedSelected = false;
                    for (WorkflowProcess pv : processVers) {
                        if (pv.equals(process))
                            removedSelected = true;
                        else
                            process.remove(pv);
                    }
                    if (removedSelected) {
                        WorkflowProcess sel = null;
                        for (WorkflowProcess toSel : process.getAllProcessVersions()) {
                            if (!toSel.equals(process)) {
                                sel = toSel;
                                break;
                            }
                        }
                        setSelection(sel);
                    } else {
                        setSelection(process); // just force refresh
                    }
                }
            }
        });
    }

    return menu;
}

From source file:com.centurylink.mdw.plugin.designer.properties.WorkflowAssetVersionsSection.java

License:Apache License

private Menu createContextMenu(Shell shell) {
    Menu menu = new Menu(shell, SWT.POP_UP);

    final StructuredSelection selection = (StructuredSelection) tableEditor.getTableViewer().getSelection();
    // open/*  w  ww  . j a va  2  s  .  co m*/
    if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowAsset) {
        final WorkflowAsset asset = (WorkflowAsset) selection.getFirstElement();

        MenuItem openItem = new MenuItem(menu, SWT.PUSH);
        openItem.setText("Open");
        openItem.setImage(workflowAsset.getIconImage());
        openItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                openAsset(asset);
            }
        });
    }
    // view comments
    if (selection.size() == 1 && selection.getFirstElement() instanceof WorkflowAsset) {
        final WorkflowAsset asset = (WorkflowAsset) selection.getFirstElement();

        MenuItem viewCommentsItem = new MenuItem(menu, SWT.PUSH);
        viewCommentsItem.setText("View Comments");
        ImageDescriptor viewCommentsImageDesc = MdwPlugin.getImageDescriptor("icons/view.gif");
        viewCommentsItem.setImage(viewCommentsImageDesc.createImage());
        viewCommentsItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                openViewCommentsDialog(asset);
            }
        });
    }
    // delete
    if (!selection.isEmpty() && !workflowAsset.getProject().isProduction()
            && workflowAsset.isUserAuthorized(UserRoleVO.ASSET_DESIGN)
            && (selection.size() == 1 && ((WorkflowAsset) selection.getFirstElement()).isLatestVersion()
                    || MdwPlugin.getSettings().isAllowDeleteArchivedProcesses())) {
        MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
        deleteItem.setText("Delete...");
        ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
        deleteItem.setImage(deleteImageDesc.createImage());
        deleteItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (selection.size() >= 1 && selection.getFirstElement() instanceof WorkflowAsset) {
                    WorkflowAsset[] assets = new WorkflowAsset[selection.size()];
                    int idx = 0;
                    for (Iterator<?> iter = selection.iterator(); iter.hasNext();) {
                        assets[idx] = (WorkflowAsset) iter.next();
                        idx++;
                    }
                    WorkflowElementActionHandler actionHandler = new WorkflowElementActionHandler();
                    actionHandler.delete(assets);
                    boolean removedSelected = false;
                    for (WorkflowAsset a : assets) {
                        if (a.equals(workflowAsset))
                            removedSelected = true;
                    }
                    if (removedSelected) {
                        WorkflowAsset sel = null;
                        for (WorkflowAsset toSel : workflowAsset.getAllVersions()) {
                            if (!toSel.equals(workflowAsset)) {
                                sel = toSel;
                                break;
                            }
                        }
                        workflowAsset.fireElementChangeEvent(ChangeType.ELEMENT_DELETE, null);
                        setSelection(sel);
                    } else {
                        // just remove and refresh
                        for (WorkflowAsset a : assets)
                            workflowAsset.getProject().removeWorkflowAsset(a);
                        setSelection(workflowAsset);
                    }
                }
            }
        });
    }

    return menu;
}

From source file:com.centurylink.mdw.plugin.designer.views.ProcessInstanceListView.java

License:Apache License

private Menu createContextMenu(Shell shell) {
    Menu menu = new Menu(shell, SWT.POP_UP);

    final StructuredSelection selection = (StructuredSelection) getTableViewer().getSelection();
    if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
        final ProcessInstanceVO processInstanceInfo = (ProcessInstanceVO) selection.getFirstElement();

        // open instance
        MenuItem openItem = new MenuItem(menu, SWT.PUSH);
        openItem.setText("Open");
        ImageDescriptor openImageDesc = MdwPlugin.getImageDescriptor("icons/process.gif");
        openItem.setImage(openImageDesc.createImage());
        openItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                handleOpen(processInstanceInfo);
            }//from ww w.  java  2  s . c  o m
        });

        // owning document
        if (OwnerType.DOCUMENT.equals(processInstanceInfo.getOwner())
                || OwnerType.TESTER.equals(processInstanceInfo.getOwner())) {
            MenuItem docItem = new MenuItem(menu, SWT.PUSH);
            docItem.setText("View Owning Document");
            ImageDescriptor docImageDesc = MdwPlugin.getImageDescriptor("icons/doc.gif");
            docItem.setImage(docImageDesc.createImage());
            docItem.addSelectionListener(new SelectionAdapter() {
                public void widgetSelected(SelectionEvent e) {
                    IStorage storage = new DocumentStorage(workflowProject,
                            new DocumentReference(processInstanceInfo.getOwnerId(), null));
                    final IStorageEditorInput input = new StorageEditorInput(storage);
                    final IWorkbenchPage page = MdwPlugin.getActivePage();
                    if (page != null) {
                        BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
                            public void run() {
                                try {
                                    page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
                                } catch (PartInitException ex) {
                                    PluginMessages.uiError(ex, "View Document", workflowProject);
                                }
                            }
                        });
                    }
                }
            });
        }

        // instance hierarchy
        MenuItem hierarchyItem = new MenuItem(menu, SWT.PUSH);
        hierarchyItem.setText("Instance Hierarchy");
        ImageDescriptor hierarchyImageDesc = MdwPlugin.getImageDescriptor("icons/hierarchy.gif");
        hierarchyItem.setImage(hierarchyImageDesc.createImage());
        hierarchyItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                WorkflowProcess pv = new WorkflowProcess(processVersion);
                pv.setProcessVO(processVersion.getProcessVO());
                pv.setProcessInstance(processInstanceInfo);
                new WorkflowElementActionHandler().showHierarchy(pv);
            }
        });
    }

    // delete
    if (!selection.isEmpty() && !processVersion.getProject().isProduction()
            && processVersion.isUserAuthorized(UserRoleVO.PROCESS_EXECUTION)) {
        MenuItem deleteItem = new MenuItem(menu, SWT.PUSH);
        deleteItem.setText("Delete...");
        ImageDescriptor deleteImageDesc = MdwPlugin.getImageDescriptor("icons/delete.gif");
        deleteItem.setImage(deleteImageDesc.createImage());
        deleteItem.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (selection.size() == 1 && selection.getFirstElement() instanceof ProcessInstanceVO) {
                    ProcessInstanceVO pii = (ProcessInstanceVO) selection.getFirstElement();
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete",
                            "Delete process instance ID: " + pii.getId() + " for workflow project '"
                                    + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<ProcessInstanceVO>();
                        instances.add((ProcessInstanceVO) selection.getFirstElement());
                        handleDelete(instances);
                    }
                } else {
                    if (MessageDialog.openConfirm(getSite().getShell(), "Confirm Delete",
                            "Delete selected process instances for workflow project '"
                                    + processVersion.getProject().getName() + "'?")) {
                        List<ProcessInstanceVO> instances = new ArrayList<ProcessInstanceVO>();
                        for (Object instance : selection.toArray()) {
                            if (instance instanceof ProcessInstanceVO)
                                instances.add((ProcessInstanceVO) instance);
                        }
                        handleDelete(instances);
                    }
                }
            }
        });
    }

    return menu;
}

From source file:com.clustercontrol.infra.view.action.DeleteInfraFileAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    InfraFileManagerView view = getView(event);
    if (view == null) {
        m_log.info("execute: view is null");
        return null;
    }// w ww. j  a  v  a 2 s.c  o  m

    List<String> fileIdList = getSelectedInfraFileIdList(view);
    if (fileIdList.isEmpty()) {
        return null;
    }

    StructuredSelection selection = null;
    if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
        selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
    }
    if (selection == null || selection.isEmpty()) {
        return null;
    }
    Map<String, List<String>> map = new ConcurrentHashMap<String, List<String>>();
    for (Object object : selection.toList()) {
        String managerName = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.MANAGER_NAME);
        if (map.get(managerName) == null) {
            map.put(managerName, new ArrayList<String>());
        }
    }

    StringBuffer strFileIds = new StringBuffer();
    String tmpFileId = null;
    for (Object object : selection.toList()) {
        String managerName = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.MANAGER_NAME);
        tmpFileId = (String) ((ArrayList<?>) object).get(GetInfraFileManagerTableDefine.FILE_ID);
        map.get(managerName).add(tmpFileId);
        if (strFileIds.length() == 0) {
            strFileIds.append(tmpFileId);
        } else {
            strFileIds.append(", " + tmpFileId);
        }
    }

    if (MessageDialog.openConfirm(null, Messages.getString("confirmed"),
            Messages.getString("message.infra.confirm.action",
                    new Object[] { Messages.getString("file"), Messages.getString("delete"), strFileIds }))) {

        Map<String, String> errMsg = new ConcurrentHashMap<String, String>();
        for (Map.Entry<String, List<String>> entry : map.entrySet()) {
            String managerName = entry.getKey();
            InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
            try {
                wrapper.deleteInfraFileList(entry.getValue());
            } catch (Exception e) {
                m_log.error(e);
                errMsg.put(managerName, HinemosMessage.replace(e.getMessage()));
            }
        }

        if (errMsg.isEmpty()) {
            String action = Messages.getString("delete");
            InfraFileUtil.showSuccessDialog(action, strFileIds.toString());
        } else {
            UIManager.showMessageBox(errMsg, true);
        }
        // ?
        view.update();
    }

    return null;
}

From source file:com.clustercontrol.infra.view.action.DownloadInfraFileAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    InfraFileManagerView view = getView(event);
    if (view == null) {
        m_log.info("execute: view is null");
        return null;
    }//  ww w. j ava  2  s.  c o m

    InfraFileInfo info = InfraFileUtil.getSelectedInfraFileInfo(view);
    if (info == null) {
        return null;
    }

    String action = Messages.getString("download");

    FileDialog fd = new FileDialog(window.getShell(), SWT.SAVE);
    String fileName = info.getFileName();
    fd.setFileName(fileName);
    String selectedFilePath = null;
    try {
        selectedFilePath = fd.open();
    } catch (Exception e) {
        m_log.error(e);
        InfraFileUtil.showFailureDialog(action, HinemosMessage.replace(e.getMessage()));
        return null;
    }

    // path is null when dialog cancelled
    if (null != selectedFilePath) {
        StructuredSelection selection = null;
        if (view.getComposite().getTableViewer().getSelection() instanceof StructuredSelection) {
            selection = (StructuredSelection) view.getComposite().getTableViewer().getSelection();
        }
        String managerName = null;
        if (selection != null && selection.isEmpty() == false) {
            managerName = (String) ((ArrayList<?>) selection.getFirstElement())
                    .get(GetInfraFileManagerTableDefine.MANAGER_NAME);
        }
        InfraEndpointWrapper wrapper = InfraEndpointWrapper.getWrapper(managerName);
        FileOutputStream fos = null;
        try {
            DataHandler dh = wrapper.downloadInfraFile(info.getFileId(), fileName);
            fos = new FileOutputStream(new File(selectedFilePath));
            dh.writeTo(fos);
            if (ClusterControlPlugin.isRAP()) {
                FileDownloader.openBrowser(window.getShell(), selectedFilePath, fileName);
            } else {
                InfraFileUtil.showSuccessDialog(action, info.getFileId());
            }
            wrapper.deleteDownloadedInfraFile(fileName);
        } catch (Exception e) {
            m_log.error(e);
            InfraFileUtil.showFailureDialog(action, HinemosMessage.replace(e.getMessage()));
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }
        }
    }

    return null;
}

From source file:com.foglyn.helpers.FBStatusesComboViewer.java

License:Open Source License

public Set<StatusID> getSelectedStatuses() {
    StructuredSelection ssel = (StructuredSelection) getSelection();
    if (ssel.isEmpty()) {
        return null;
    }// www  .  ja v  a2s.co m

    Assert.isTrue(ssel.size() == 1);

    Object obj = ssel.getFirstElement();
    if (HelperConstants.NULL_VALUE.equals(obj)) {
        return null;
    }

    FBStatusItem fbsi = (FBStatusItem) obj;
    return fbsi.getStatuses();
}

From source file:com.google.dart.tools.ui.actions.ShowInFinderAction.java

License:Open Source License

public void updateEnablement() {

    boolean enabled = false;

    ISelection selection = getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (!structuredSelection.isEmpty() && structuredSelection.getFirstElement() instanceof IResource) {
            enabled = true;/*from w ww . j a va  2 s  .co  m*/
        }
    }

    setEnabled(enabled);
}

From source file:com.google.dart.tools.ui.actions.ShowInFinderAction.java

License:Open Source License

@Override
protected void doRun(Event event, UIInstrumentationBuilder instrumentation) {
    ISelection selection = getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.isEmpty()) {
            return;
        }/*  ww w .ja  v  a  2 s  . c o  m*/
        Object element = structuredSelection.getFirstElement();
        if (!(element instanceof IResource)) {
            return;
        }
        IResource resource = (IResource) element;
        instrumentation.data("path", resource.getLocation().toOSString());
        String path = resource.getLocation().toOSString();
        try {
            if (SystemUtils.IS_OS_LINUX) {
                try {
                    new ProcessBuilder("/usr/bin/nautilus", path).start();
                } catch (IOException e) {
                    // no Nautilus, try generic xdg-open
                    if (resource instanceof IFile) {
                        path = resource.getParent().getLocation().toOSString();
                    }
                    new ProcessBuilder("/usr/bin/xdg-open", path).start();
                }
                return;
            }
            if (SystemUtils.IS_OS_MAC) {
                new ProcessBuilder("/usr/bin/open", "-R", path).start();
                return;
            }
            if (SystemUtils.IS_OS_WINDOWS) {
                new ProcessBuilder("Explorer.exe", "/select,", path).start();
                return;
            }
        } catch (IOException e) {
            instrumentation.record(e);
            ErrorDialog.openError(window.getShell(), null, null,
                    DartToolsPlugin.createErrorStatus("Cannot " + getText(), e));
        }
    }
}