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

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

Introduction

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

Prototype

@Override
    public Object getFirstElement() 

Source Link

Usage

From source file:com.apicloud.navigator.dialogs.RunMobileDialog.java

License:Open Source License

protected void buttonPressed(int buttonId) {
    if (buttonId == 0) {
        StructuredSelection ss = (StructuredSelection) this.list.getSelection();
        IProject project = (IProject) ss.getFirstElement();
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        if (validate(getID(project), project)) {

            final SyncApplicationDialog sad = new SyncApplicationDialog(shell, aMobiles, iMobiles, project);
            final CountDownLatch threadSignal = new CountDownLatch(aMobiles.size() + iMobiles.size());
            sad.open();/*from ww  w.  ja va2  s .c  om*/
            sad.run(threadSignal);
            Job job = new WorkspaceJob("") {
                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    try {
                        threadSignal.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    sad.finish();
                    return Status.OK_STATUS;
                }
            };
            job.schedule();
            close();
        } else if (buttonId == 1) {
            close();
        } else {
            close();
        }
    } else {
        close();
    }
}

From source file:com.apicloud.navigator.ui.wizards.TempleteFarmeWizardPage.java

License:Open Source License

/**
 * Create contents of the wizard./*w ww .  ja va2s .  c o m*/
 * @param parent
 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);

    setControl(container);
    GridLayout gl_container = new GridLayout(3, false);
    gl_container.marginRight = 20;
    gl_container.marginHeight = 0;
    gl_container.marginLeft = 20;
    container.setLayout(gl_container);

    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));

    Label lblNewLabel = new Label(composite, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel.setText("\u6240\u5C5E\u9879\u76EE:");

    this.list = new ComboViewer(composite, SWT.NONE | SWT.READ_ONLY);
    this.list.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    this.list.setLabelProvider(new ProjectLabelProvider());
    this.list.setContentProvider(new ArrayContentProvider());
    this.list.setInput(projects);
    this.list.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection ss = (StructuredSelection) list.getSelection();
            IProject p = (IProject) ss.getFirstElement();
            project = p;
            selectProject(p);
        }
    });

    Label lblNewLabel_1 = new Label(composite, SWT.NONE);
    lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel_1.setText(Messages.PAGENAME);

    pageName = new Text(composite, SWT.BORDER);
    pageName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    pageName.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            setPageComplete(validatePage());
        }
    });

    Composite composite_4 = new Composite(container, SWT.NONE);
    GridData gd_composite_4 = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2);
    gd_composite_4.widthHint = 20;
    composite_4.setLayoutData(gd_composite_4);

    Composite composite_1 = new Composite(container, SWT.NONE);
    composite_1.setLayout(new GridLayout(1, false));
    GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 2);
    gd_composite_1.widthHint = 240;
    gd_composite_1.heightHint = 480;
    composite_1.setLayoutData(gd_composite_1);

    lblNewLabel_3 = new Label(composite_1, SWT.NONE);
    lblNewLabel_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
    lblNewLabel_3.setImage(AuthenticActivator.getImage(pages.get(0).getReViewImage()));

    Composite composite_2 = new Composite(container, SWT.NONE);
    composite_2.setLayout(new GridLayout(2, false));
    composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Label lblNewLabel_2 = new Label(composite_2, SWT.NONE);
    lblNewLabel_2.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    lblNewLabel_2.setText(Messages.PAGEFREAWORK);

    Composite composite_3 = new Composite(composite_2, SWT.NONE);
    composite_3.setLayout(new GridLayout(1, false));
    GridData gd_composite_3 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_composite_3.heightHint = 350;
    composite_3.setLayoutData(gd_composite_3);
    TableViewer UIViewer = createTable(composite_3);
    UIViewer.setInput(pages);

    UIViewer.setSelection(new StructuredSelection(pages.get(0)));
    new Label(container, SWT.NONE);
    page = pages.get(0);

    updateDate();
    setPageComplete(validatePage());
}

From source file:com.apicloud.navigator.ui.wizards.TempleteFarmeWizardPage.java

License:Open Source License

protected boolean validatePage() {
    canFinish = false;/* www . java  2  s.  com*/
    StructuredSelection ss = (StructuredSelection) list.getSelection();
    IProject p = (IProject) ss.getFirstElement();
    if (project == null) {
        setPageComplete(false);
        setErrorMessage("\u8BF7\u5148\u9009\u62E9\u4E00\u4E2A\u9879\u76EE!");
        return false;
    }
    if ("".equals(pageName.getText())) {
        setPageComplete(false);
        setErrorMessage(Messages.PAGENAMEISNOTNULL);
        return false;
    }

    String fileName = pageName.getText() + "_window.html";

    IResource resource = p.findMember(new Path("/html/" + fileName));
    if (resource != null) {
        setPageComplete(false);
        setErrorMessage("doub");
        return false;
    }
    setErrorMessage(null);
    setMessage(null);
    canFinish = true;
    return true;

}

From source file:com.aptana.editor.common.internal.scripting.TemplateSelectionPage.java

License:Open Source License

public void selectionChanged(SelectionChangedEvent event) {
    StructuredSelection selection = (StructuredSelection) event.getSelection();
    if (!selection.isEmpty()) {
        setPreviewContent(((TemplateElement) selection.getFirstElement()));
    } else {/*from   w w w.  j a v  a 2 s  .  c o  m*/
        setPreviewContent(null);
    }
}

From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
 *///from   w  ww  .  j  ava2  s .com
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);

    Composite content = new Composite(dialogArea, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    content.setLayoutData(gd);

    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    content.setLayout(layout);

    createHeader(content);

    pattern = new Text(content, SWT.SINGLE | SWT.BORDER);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    pattern.setLayoutData(gd);
    createExtras(content);
    createLabels(content);

    list = new TableViewer(content, (multi ? SWT.MULTI : SWT.SINGLE) | SWT.BORDER | SWT.V_SCROLL | SWT.VIRTUAL);
    list.setContentProvider(contentProvider);
    list.setLabelProvider(getItemsListLabelProvider());
    list.setInput(new Object[0]);
    list.setItemCount(contentProvider.getElements(null).length);
    gd = new GridData(GridData.FILL_BOTH);
    list.getTable().setLayoutData(gd);

    createPopupMenu();

    pattern.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            applyFilter();
        }
    });

    pattern.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_DOWN) {
                if (list.getTable().getItemCount() > 0) {
                    list.getTable().setFocus();
                }
            }
        }
    });

    list.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            handleSelected(selection);
        }
    });

    list.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            handleDoubleClick();
        }
    });

    list.getTable().addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {

            if (e.keyCode == SWT.DEL) {

                List<?> selectedElements = ((StructuredSelection) list.getSelection()).toList();

                Object item = null;
                boolean isSelectedHistory = true;

                for (Iterator<?> it = selectedElements.iterator(); it.hasNext();) {
                    item = it.next();
                    if (item instanceof ItemsListSeparator || !isHistoryElement(item)) {
                        isSelectedHistory = false;
                        break;
                    }
                }
                if (isSelectedHistory) {
                    removeSelectedItems(selectedElements);
                }
            }

            if (e.keyCode == SWT.ARROW_UP && (e.stateMask & SWT.SHIFT) != 0 && (e.stateMask & SWT.CTRL) != 0) {
                StructuredSelection selection = (StructuredSelection) list.getSelection();

                if (selection.size() == 1) {
                    Object element = selection.getFirstElement();
                    if (element.equals(list.getElementAt(0))) {
                        pattern.setFocus();
                    }
                    if (list.getElementAt(
                            list.getTable().getSelectionIndex() - 1) instanceof ItemsListSeparator) {
                        list.getTable().setSelection(list.getTable().getSelectionIndex() - 1);
                    }
                    list.getTable().notifyListeners(SWT.Selection, new Event());

                }
            }

            if (e.keyCode == SWT.ARROW_DOWN && (e.stateMask & SWT.SHIFT) != 0
                    && (e.stateMask & SWT.CTRL) != 0) {

                if (list.getElementAt(list.getTable().getSelectionIndex() + 1) instanceof ItemsListSeparator) {
                    list.getTable().setSelection(list.getTable().getSelectionIndex() + 1);
                }
                list.getTable().notifyListeners(SWT.Selection, new Event());
            }

        }
    });

    createExtendedContentArea(content);

    details = new DetailsContentViewer(content, SWT.BORDER | SWT.FLAT);
    details.setVisible(toggleStatusLineAction.isChecked());
    details.setContentProvider(new NullContentProvider());
    details.setLabelProvider(getDetailsLabelProvider());

    applyDialogFont(content);

    restoreDialog(getDialogSettings());

    if (initialPatternText != null) {
        pattern.setText(initialPatternText);
    }

    switch (selectionMode) {
    case CARET_BEGINNING:
        pattern.setSelection(0, 0);
        break;
    case FULL_SELECTION:
        pattern.setSelection(0, initialPatternText.length());
        break;
    }

    // apply filter even if pattern is empty (display history)
    applyFilter();

    return dialogArea;
}

From source file:com.aptana.editor.php.internal.ui.dialog.CustomFilteredItemsSelectionDialog.java

License:Open Source License

/**
 * Refreshes the details field according to the current selection in the items list.
 *//*from www. j ava  2 s.  c o m*/
private void refreshDetails() {
    StructuredSelection selection = getSelectedItems();

    switch (selection.size()) {
    case 0:
        details.setInput(null);
        break;
    case 1:
        details.setInput(selection.getFirstElement());
        break;
    default:
        details.setInput(
                NLS.bind(Messages.FilteredItemsSelectionDialog_SelectedItems, new Integer(selection.size())));
        break;
    }

}

From source file:com.aptana.ide.core.ui.preferences.ProjectNaturesPage.java

License:Open Source License

private void updateButtons() {
    StructuredSelection selection = (StructuredSelection) listViewer.getSelection();
    makePrimaryButton.setEnabled(!selection.isEmpty() && !isPrimary(selection.getFirstElement()));
    restoreButton.setEnabled(modified || isPrimaryModified());
}

From source file:com.aptana.ide.server.ui.generic.dialogs.ServerTypeSelectionDialog.java

License:Open Source License

private IServerType calcResult() {
    StructuredSelection ss = (StructuredSelection) viewer.getSelection();
    if (!ss.isEmpty()) {
        return (IServerType) ss.getFirstElement();
    } else {/*from   w w w.j a va  2s . co  m*/
        return null;
    }
}

From source file:com.aptana.ide.server.ui.views.actions.OpenConsole.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
 *//*from  ww w  .  j  a v  a2 s.c  o  m*/
public void selectionChanged(SelectionChangedEvent event) {
    ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        setEnabled(false);
    }
    if (selection instanceof StructuredSelection) {
        StructuredSelection ss = (StructuredSelection) selection;
        if (ss.size() == 1) {
            Object firstElement = ss.getFirstElement();
            if (firstElement instanceof IServer) {
                server = (IServer) firstElement;
                ICanOpenConsole adapter = (ICanOpenConsole) server.getAdapter(ICanOpenConsole.class);
                setEnabled(adapter != null || consoles.get(server) != null);
                return;
            }
        }
    }
    setEnabled(false);
}

From source file:com.aptana.ide.server.ui.views.actions.OpenLogAction.java

License:Open Source License

private void fillManager(MenuManager mn) {
    ISelection selection = provider.getSelection();
    if (selection instanceof StructuredSelection && !selection.isEmpty()) {
        StructuredSelection ss = (StructuredSelection) selection;
        final IServer server = (IServer) ss.getFirstElement();
        ILog[] logs = server.getAllLogs();
        final Object logOpener = server.getAdapter(ILogOpener.class);
        if (logs != null) {
            for (final ILog log : logs) {
                Action action = new Action() {

                    public void run() {
                        if (logOpener instanceof ILogOpener) {
                            ((ILogOpener) logOpener).openLog(log);
                        } else {
                            openLogView(log.getURI(), server.getName());
                        }/*from   w  ww.  ja v  a2s  . c o  m*/
                    }

                };
                if (log instanceof INamedLog) {
                    action.setText(((INamedLog) log).getName());
                } else {
                    action.setText(getLogName(log.getURI()));
                }
                mn.add(action);
            }
        }
    }
}