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

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

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:com.aptana.ide.samples.ui.SamplesView.java

License:Open Source License

/**
 * Selects and reveals a samples entry with the given name
 * //from ww w . j a  va  2s.  co  m
 * @param entryName
 */
public void selectAndReveal(String entryName) {
    if (entryName == null) {
        return;
    }
    if (_viewer.getInput() == SamplesViewContentProvider.LOADING) {
        this.firstReveal = entryName;
    }
    SamplesInfo[] infos = SamplesManager.getInstance().getSamplesInfos();
    for (int i = 0; i < infos.length; i++) {
        if (infos[i].getName().equals(entryName)) {
            _viewer.expandToLevel(infos[i], 1);
            _viewer.setSelection(new StructuredSelection(infos[i]), true);
            break;
        }
    }
}

From source file:com.aptana.ide.search.AptanaFileSearchPage.java

License:Open Source License

/**
 * custom handling of changes in search result for mathces mode
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#handleSearchResultChanged(org.eclipse.search.ui.SearchResultEvent)
 *//*from  www  .  j  ava 2s  .  c o  m*/
protected void handleSearchResultChanged(final SearchResultEvent e) {
    if (this.layout != AptanaFileSearchPage.LAYOUT_MATCHES) {
        super.handleSearchResultChanged(e);
        return;
    }
    if (e instanceof MatchEvent) {
        MatchEvent me = (MatchEvent) e;
        int kind = me.getKind();
        if ((Display.getCurrent() != null) && (kind == MatchEvent.REMOVED)) {
            TableViewer cc = (TableViewer) this.getViewer();
            Table table = cc.getTable();
            int selectionIndex = table.getSelectionIndex();
            cc.refresh();
            if (selectionIndex != -1) {
                if (selectionIndex < table.getItemCount()) {
                    TableItem item = cc.getTable().getItem(selectionIndex);
                    cc.setSelection(new StructuredSelection(item.getData()));
                }
            }
        } else {
            super.handleSearchResultChanged(e);
        }
        // elementsChanged(me.getMatches());

    } else if (e instanceof RemoveAllEvent) {
        super.handleSearchResultChanged(e);
    }
}

From source file:com.aptana.ide.search.ui.filesystem.AptanaFileSystemSearchPage.java

License:Open Source License

/**
 * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#handleSearchResultChanged(org.eclipse.search.ui.SearchResultEvent)
 *//*from   w  ww.  j a v a2  s  .  co  m*/
protected void handleSearchResultChanged(final SearchResultEvent e) {
    if (this.layout != LAYOUT_MATCHES) {
        super.handleSearchResultChanged(e);
        return;
    }
    if (e instanceof MatchEvent) {
        MatchEvent me = (MatchEvent) e;
        int kind = me.getKind();
        if ((Display.getCurrent() != null) && (kind == MatchEvent.REMOVED)) {
            TableViewer cc = (TableViewer) getViewer();
            Table table = cc.getTable();
            int selectionIndex = table.getSelectionIndex();
            cc.refresh();
            if (selectionIndex != -1) {
                if (selectionIndex < table.getItemCount()) {
                    TableItem item = cc.getTable().getItem(selectionIndex);
                    cc.setSelection(new StructuredSelection(item.getData()));
                }
            }
        } else {
            super.handleSearchResultChanged(e);
        }
    } else if (e instanceof RemoveAllEvent) {
        super.handleSearchResultChanged(e);
    }
}

From source file:com.aptana.ide.server.jetty.ShowProjectClient.java

License:Open Source License

/**
 * @see com.aptana.ide.server.jetty.comet.CometClient#getResponse(java.lang.String,
 *      java.lang.Object)/* w  ww.  ja  va2s  . co  m*/
 */
protected Object getResponse(String toChannel, Object request) {
    if (SHOW_PROJECT.equals(toChannel)) {
        if (request instanceof Map) {
            Map requestData = (Map) request;
            if (requestData.containsKey(PROJECT)) {
                final String projectName = requestData.get(PROJECT).toString();

                UIJob job = new UIJob(Messages.ShowProjectClient_Job_DisplayProject) {

                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        for (IProject project : CoreUIUtils.getWorkspaceRoot().getProjects()) {
                            if (projectName.equals(project.getName())) {
                                try {
                                    IViewPart view = CoreUIUtils.showView(NAVIGATOR_ID);
                                    if (view instanceof CommonNavigator) {
                                        CommonNavigator nav = (CommonNavigator) view;
                                        nav.selectReveal(new StructuredSelection(project));
                                        nav.getCommonViewer().expandToLevel(project, 1);
                                    }
                                } catch (PartInitException e) {
                                }
                                break;
                            }
                        }
                        return Status.OK_STATUS;
                    }

                };
                job.schedule();
            }
        }
    }
    return null;
}

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

License:Open Source License

/**
 * @param srv
 */
public void select(IServer srv) {
    serverViewer.setSelection(new StructuredSelection(srv), true);
}

From source file:com.aptana.ide.syncing.doms.Sync.java

License:Open Source License

/**
 * Uploads an IAdaptable that represents a file.
 * //  www.jav  a2  s.c  om
 * @param file
 *            the IAdaptable object
 */
public static void upload(IAdaptable file) {
    upload(new StructuredSelection(file));
}

From source file:com.aptana.ide.syncing.doms.Sync.java

License:Open Source License

/**
 * Downloads an IAdaptable that represents a file.
 * /*from w ww .j  a  va2 s  .c  o  m*/
 * @param file
 *            the IAdaptable object
 */
public static void download(IAdaptable file) {
    download(new StructuredSelection(file));
}

From source file:com.aptana.ide.syncing.ui.actions.Sync.java

License:Open Source License

/**
 * Uploads an IAdaptable that represents a file.
 * /*from   www. j av  a 2s.  c  om*/
 * @param file
 *            the IAdaptable object
 */
private static void upload(IAdaptable file) {
    upload(new StructuredSelection(file));
}

From source file:com.aptana.ide.syncing.ui.actions.Sync.java

License:Open Source License

/**
 * Downloads an IAdaptable that represents a file.
 * //  www  . j  a  va2 s .  co m
 * @param file
 *            the IAdaptable object
 */
private static void download(IAdaptable file) {
    download(new StructuredSelection(file));
}

From source file:com.aptana.ide.syncing.ui.dialogs.SiteConnectionsEditorDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);

    setTitle(Messages.SiteConnectionsEditorDialog_Title);
    setMessage(Messages.SiteConnectionsEditorDialog_Message);

    Composite container = new Composite(dialogArea, SWT.NONE);
    container.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    container.setLayout(GridLayoutFactory.swtDefaults()
            .margins(convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN),
                    convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN))
            .spacing(convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING),
                    convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING))
            .create());/*  w  w  w . ja va2  s. c o  m*/

    SashForm sashForm = new SashForm(container, SWT.HORIZONTAL);
    sashForm.setLayoutData(GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 400).grab(true, true).create());

    /* column 1 - the list of connections */
    Group group = new Group(sashForm, SWT.NONE);
    group.setText(Messages.SiteConnectionsEditorDialog_LBL_ConnectionGroup);
    group.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    group.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).create());

    sitesViewer = new ListViewer(group, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    sitesViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(2, 1).create());
    sitesViewer.setContentProvider(ArrayContentProvider.getInstance());
    sitesViewer.setLabelProvider(new SitesLabelProvider());
    sitesViewer.setComparator(new SitesSorter());
    sitesViewer.setInput(sites);

    addButton = new Button(group, SWT.PUSH);
    addButton.setLayoutData(GridDataFactory.swtDefaults().create());
    addButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/add.gif")); //$NON-NLS-1$
    addButton.setToolTipText(StringUtil.ellipsify(CoreStrings.ADD));

    removeButton = new Button(group, SWT.PUSH);
    removeButton.setLayoutData(GridDataFactory.swtDefaults().create());
    removeButton.setImage(SWTUtils.getImage(UIPlugin.getDefault(), "/icons/delete.gif")); //$NON-NLS-1$
    removeButton.setToolTipText(CoreStrings.REMOVE);

    /* column 2 - the details of the selected connection */
    Composite composite = new Composite(sashForm, SWT.NONE);
    composite.setLayout(GridLayoutFactory.fillDefaults().create());
    sitePropertiesWidget = new SiteConnectionPropertiesWidget(composite, SWT.NONE, this);
    sitePropertiesWidget.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    sitePropertiesWidget.setSource(null);

    sashForm.setWeights(new int[] { 30, 70 });

    /* -- */
    sitesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            ISiteConnection selection = (ISiteConnection) ((IStructuredSelection) event.getSelection())
                    .getFirstElement();
            if (selection != sitePropertiesWidget.getSource()) {
                if (doSelectionChange()) {
                    sitePropertiesWidget.setSource(selection);
                } else {
                    sitesViewer.setSelection(new StructuredSelection(sitePropertiesWidget.getSource()), true);
                }
            }
            removeButton.setEnabled(
                    !event.getSelection().isEmpty() && selection != DefaultSiteConnection.getInstance());
        }
    });

    MenuManager menuManager = new MenuManager();
    createActions(menuManager);
    sitesViewer.getControl().setMenu(menuManager.createContextMenu(sitesViewer.getControl()));

    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (doSelectionChange()) {
                setCreateNew(Messages.SiteConnectionsEditorDialog_LBL_NewConnection, null, null);
            } else {
                sitesViewer.setSelection(new StructuredSelection(sitePropertiesWidget.getSource()), true);
            }
        }
    });
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!sitesViewer.getSelection().isEmpty()) {
                if (MessageDialog.openConfirm(getShell(),
                        Messages.SiteConnectionsEditorDialog_DeleteConfirm_Title,
                        Messages.SiteConnectionsEditorDialog_DeleteConfirm_Message)) {
                    ISiteConnection selection = (ISiteConnection) ((IStructuredSelection) sitesViewer
                            .getSelection()).getFirstElement();
                    int newSelectionIndex = sitesViewer.getList().getSelectionIndex() - 1;

                    SyncingPlugin.getSiteConnectionManager().removeSiteConnection(selection);
                    sites.remove(selection);
                    sitePropertiesWidget.setSource(null);
                    sitesViewer.refresh();
                    if (newSelectionIndex > -1 && newSelectionIndex < sitesViewer.getList().getItemCount()) {
                        setSelection((newSelectionIndex == 0) ? DefaultSiteConnection.getInstance()
                                : sites.get(newSelectionIndex - 1));
                    }
                }
            }
        }
    });

    return dialogArea;
}