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

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

Introduction

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

Prototype

public Object[] toArray();

Source Link

Document

Returns the elements in this selection as an array.

Usage

From source file:com.nokia.s60ct.gui.actions.DeleteConfigurationAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();//  w  w  w.  j  a  va  2 s  .  c  om
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        selectToBeRemoved(objects);
    }
    if (!selectedObjects.isEmpty()) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);

}

From source file:com.nokia.s60ct.gui.actions.DeleteFrameAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();//from  w  w w .  j ava 2  s . c om
    boolean isTemplate = false;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length != 0) {
            Frame frame = (Frame) objects[0];
            isTemplate = frame.isTemplate();
            selectToBeRemoved(objects);
        }
    }
    if (!selectedObjects.isEmpty() && !isTemplate) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);
}

From source file:com.nokia.s60ct.gui.actions.DeleteLeafSettingDelegator.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();// www .  j ava2  s . c om
    boolean isTemplate = false;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length != 0) {
            LeafSettingDelegator lsd = (LeafSettingDelegator) objects[0];
            Frame frame = (Frame) lsd.eContainer();
            isTemplate = frame.isTemplate();
            selectToBeRemoved(objects);
        }
    }
    if (!selectedObjects.isEmpty() && PARENT_FEATURE != null && isTemplate) {
        action.setEnabled(true);
    } else
        action.setEnabled(false);

}

From source file:com.nokia.s60ct.gui.actions.MoveDownFrameAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();/* w  w  w . j a va2  s . com*/
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length != 0) {
            Frame frame = (Frame) objects[0];

            if (frame.isTemplate()) {
                action.setEnabled(false);
            } else {
                this.frame = frame;
                ParentSetting parentSetting = (ParentSetting) frame.eContainer();

                List myFrames = parentSetting.getMyCurrentFrames();

                for (int i = 0; i < myFrames.size() - 1; i++) {
                    if (frame.equals(myFrames.get(i))) {
                        action.setEnabled(true);
                        return;
                    }
                }
                action.setEnabled(false);
            }
        }
    }
}

From source file:com.nokia.s60ct.gui.actions.MoveUpFrameAction.java

License:Open Source License

public void selectionChanged(IAction action, ISelection selection) {
    selectedObjects.clear();/* ww w  .  ja v a 2s .c om*/
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length != 0) {
            Frame frame = (Frame) objects[0];

            if (frame.isTemplate()) {
                action.setEnabled(false);
            } else {
                this.frame = frame;
                ParentSetting parentSetting = (ParentSetting) frame.eContainer();
                List myFrames = parentSetting.getMyCurrentFrames();

                for (int i = 0; i < myFrames.size(); i++) {
                    if (frame.equals(myFrames.get(i))) {
                        if (i == 0)
                            action.setEnabled(false);
                        else
                            action.setEnabled(true);
                        return;
                    }
                }
                action.setEnabled(false);
            }
        }
    }
}

From source file:com.nokia.s60ct.gui.actions.OpenValidationWebPageAction.java

License:Open Source License

@Override
public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length == 1 && getValidationWebPageURL() != null) {
            selectedObject = objects[0];
            action.setEnabled(true);//from www . j av  a2 s.  c  o m
        } else
            action.setEnabled(false);
    }
}

From source file:com.nokia.s60ct.gui.actions.OpenValidationWebPagePopupAction.java

License:Open Source License

@Override
public void selectionChanged(IAction action, ISelection selection) {

    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structedSelection = (IStructuredSelection) selection;
        Object[] objects = structedSelection.toArray();
        if (objects.length == 1 && getValidationWebPageURL() != null) {
            selectedObject = objects[0];
            action.setEnabled(true);/* w  w w  .  j a  va  2s.  c o m*/
        } else
            action.setEnabled(false);
    }
}

From source file:com.nokia.s60ct.search.gui.SearchPane.java

License:Open Source License

private EObject getUserSelectedEObject() {
    ISelectionProvider provider = getActiveSelectionProvider();
    if (provider != null) {
        ISelection selection = provider.getSelection();
        if (selection instanceof ITreeSelection) {
            EObject ret = null;/*from  ww  w.j a  v  a 2s. c  o  m*/
            for (TreePath path : ((ITreeSelection) selection).getPaths()) {
                for (int i = 0; i < path.getSegmentCount(); i++) {
                    if (path.getSegment(i) instanceof CenrepResourceImpl
                            && ((CenrepResourceImpl) path.getSegment(i)).getContents().size() > 0) {
                        ret = ((CenrepResourceImpl) path.getSegment(i)).getContents().get(0);
                    } else if (path.getSegment(i) instanceof EObject) {
                        ret = (EObject) path.getSegment(i);
                    }
                }
                if (ret != null) {
                    break;
                }
            }
            return ret;
        }
        if (selection instanceof IStructuredSelection) {
            IStructuredSelection structured = (IStructuredSelection) selection;
            for (Object object : structured.toArray()) {
                if (object instanceof CenrepResourceImpl
                        && ((CenrepResourceImpl) object).getContents().size() > 0) {
                    return ((CenrepResourceImpl) object).getContents().get(0);
                } else if (object instanceof EObject) {
                    return (EObject) object;
                }
            }
        }
    }
    return null;
}

From source file:com.nokia.s60tools.compatibilityanalyser.ui.views.MainView.java

License:Open Source License

private void makeActions() {
    openAnalysisWizardAction = new Action() {
        public void run() {
            showWizard();//from  www  . ja v a2s. com
        }
    };
    openAnalysisWizardAction.setText("Analysis Wizard"); //$NON-NLS-1$
    openAnalysisWizardAction.setToolTipText(Messages.getString("MainView.ToolTipForAnalysis")); //$NON-NLS-1$
    openAnalysisWizardAction
            .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.ANALYSIS_SMALL_ICON));

    openReportWizardAction = new Action() {
        public void run() {
            showReportFilterWizard(null);
        }
    };
    openReportWizardAction.setText(Messages.getString("MainView.ReportFilterWizard")); //$NON-NLS-1$
    openReportWizardAction.setToolTipText(Messages.getString("MainView.ToolTipForReportWizard")); //$NON-NLS-1$
    openReportWizardAction
            .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.FILTERATION_SMALL_ICON));

    openIssueAction = new Action() {
        public void run() {
            doubleClickIssuesAction.setCurrentSdkData(engine.getCurrentSdkData());
            doubleClickIssuesAction.run();
        }
    };
    openIssueAction.setText("Open");
    openIssueAction.setToolTipText("Opens the issue file from current SDK");

    showDiffAction = new Action() {
        public void run() {
            IStructuredSelection selectedElem = (IStructuredSelection) treeViewer.getSelection();
            String current_file = null;
            String baseline_file = null;
            if (selectedElem.getFirstElement() instanceof CompatibilityIssueFileData) {
                current_file = ((CompatibilityIssueFileData) selectedElem.getFirstElement())
                        .getCurrentIssueFile();
                baseline_file = ((CompatibilityIssueFileData) selectedElem.getFirstElement())
                        .getBaselinIssueFile();
            } else if (selectedElem.getFirstElement() instanceof CompatibilityIssueData) {
                CompatibilityIssueData issue = (CompatibilityIssueData) (selectedElem.getFirstElement());
                current_file = issue.getCurrentIssueFile();
                baseline_file = issue.getBaselineIssueFile();
            }
            if (current_file == null)
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Compatibility Analyser",
                        "Current file does not exist.");
            else if (baseline_file == null)
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Compatibility Analyser",
                        "Baseline file does not exist.");
            else if (current_file != null && baseline_file != null) {
                File left = new File(current_file);
                File right = new File(baseline_file);

                //Open the compare editor
                final CompareConfiguration cc = new CompareConfiguration();
                //left side title
                cc.setLeftLabel(left.getAbsolutePath());
                //right side title
                cc.setRightLabel(right.getAbsolutePath());
                CompareUI.openCompareEditor((new FileCompareInput(cc, left, right)));
            }
        }
    };
    showDiffAction.setText("Compare with baseline");
    showDiffAction.setToolTipText("Open the diff view of current and baseline files");

    doubleClickReportAction = new Action() {
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) tableviewer.getSelection();

            if (selection.getFirstElement() instanceof String) {
                String selectedItem = selection.getFirstElement().toString();
                if (selectedItem.equals(Messages.getString("MainView.DoubleClickHereToStartAnalysis"))) //$NON-NLS-1$
                {
                    showWizard();
                    return;
                }
            }
            if (openInwebBrowserAction.isChecked())
                openInwebBrowserAction.run();
            else if (openInXmlEditorAction.isChecked())
                openInXmlEditorAction.run();
        }
    };

    doubleClickIssuesAction = new OpenSourceFileIssuesViewAction(treeViewer);
    collapseAction = new Action() {
        public void run() {
            treeViewer.collapseAll();
        }
    };
    collapseAction.setText("Collapse all");
    collapseAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_COLLAPSEALL));

    openInwebBrowserAction = new Action("Web Browser", IAction.AS_RADIO_BUTTON) {
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) tableviewer.getSelection();
            if (isChecked() && selection.getFirstElement() instanceof ReportData) {
                IPath path = new Path(((ReportData) selection.getFirstElement()).getName());
                IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);
                String editorId = null;

                if (fileStore.fetchInfo().exists()) {
                    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    try {
                        IEditorDescriptor[] editors = PlatformUI.getWorkbench().getEditorRegistry()
                                .getEditors("test.html");

                        for (IEditorDescriptor desc : editors) {
                            if (desc.getLabel().equalsIgnoreCase("Web Browser")) {
                                editorId = desc.getId();
                                break;
                            }

                        }

                        if (editorId != null) {
                            //String id = editor.getId();
                            page.openEditor(new FileStoreEditorInput(fileStore), editorId, true,
                                    IWorkbenchPage.MATCH_ID);
                        } else
                            MessageDialog.openError(Display.getDefault().getActiveShell(),
                                    "Compatibility Analyser", "Web Browser Editor does not exist.");
                    } catch (PartInitException e) {
                        e.printStackTrace();
                    }
                } else {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), "Compatibility Analyser",
                            "File does not exist.");
                    return;
                }
            }
        }
    };
    try {
        openInwebBrowserAction.setImageDescriptor(IDE.getEditorDescriptor(".html").getImageDescriptor());
    } catch (PartInitException e1) {
        e1.printStackTrace();
    }
    openInwebBrowserAction.setChecked(true);

    clearAction = new Action() {
        public void run() {
            CompatibilityAnalyserEngine.clearReportFiles();
            updateView();
        }
    };
    clearAction.setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.CLEAR_ALL));

    filterReportAction = new Action() {
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) tableviewer.getSelection();
            Object[] selectedObjs = selection.toArray();
            String[] files = new String[selectedObjs.length];
            for (int i = 0; i < selectedObjs.length; i++) {
                if (selectedObjs[i] instanceof ReportData) {
                    ReportData report = (ReportData) selectedObjs[i];
                    files[i] = report.getName();
                } else
                    files[i] = selectedObjs[i].toString();
            }
            showReportFilterWizard(files);
            updateView();
        }
    };
    filterReportAction
            .setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.FILTERATION_SMALL_ICON));

    selectAllAction = new Action() {
        public void run() {
            tableviewer.getTable().selectAll();
        }
    };

    openInXmlEditorAction = new Action("XML Editor", IAction.AS_RADIO_BUTTON) {
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) tableviewer.getSelection();
            if (isChecked() && selection.getFirstElement() instanceof ReportData) {
                ReportData report = (ReportData) selection.getFirstElement();
                String selectedItem = report.getName();
                IPath path = new Path(selectedItem);
                IFileStore fileStore = EFS.getLocalFileSystem().getStore(path);

                if (fileStore.fetchInfo().exists()) {
                    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

                    try {
                        String id = IDE.getEditorDescriptor(".txt").getId();
                        page.openEditor(new FileStoreEditorInput(fileStore), id);

                    } catch (PartInitException e) {
                        e.printStackTrace();
                    }
                } else {
                    MessageDialog.openError(tableviewer.getControl().getShell(), "Compatibility Analyser",
                            selectedItem + " file does not exist.");
                    return;
                }
            }
        }
    };
    try {
        openInXmlEditorAction.setImageDescriptor(IDE.getEditorDescriptor(".xml").getImageDescriptor());
    } catch (PartInitException e) {
        e.printStackTrace();
    }
}

From source file:com.nokia.s60tools.imaker.internal.viewers.DebugTab.java

License:Open Source License

private void deleteSelection() {
    ISelection selection = tableViewer.getSelection();
    if (selection != null) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        Object[] objects = ss.toArray();
        for (int i = 0; i < objects.length; i++) {
            IbyEntry fe = (IbyEntry) objects[i];
            ImageContent ic = getInput();
            ic.getEntries().remove(fe);// ww w  . j a  v a  2  s. co m
        }
        tableViewer.refresh();
    }
}