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

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

Introduction

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

Prototype

public Object getFirstElement();

Source Link

Document

Returns the first element in this selection, or null if the selection is empty.

Usage

From source file:com.bb.extensions.plugin.unittests.internal.actions.UpdateMocksAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    boolean result = false;

    this.selectedElement = null;

    if (!selection.isEmpty()) {
        Object selected = selection.getFirstElement();
        if (selected instanceof MocksUnitTestsNavigatorElement) {
            this.selectedElement = (MocksUnitTestsNavigatorElement) selected;
            result = true;//from  w ww .  j  a  v  a2 s .  c o  m
        }
    }

    return result;
}

From source file:com.bb.extensions.plugin.unittests.internal.handlers.InstallUnitTestsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IProject project = null;/*from  w  w w  . j av  a2s . co m*/

    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;
        project = (IProject) strucSelection.getFirstElement();
    }

    if (project != null) {
        Wizard wizard = new InstallWizard(project);
        WizardDialog dialog = new WizardDialog(
                Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
        dialog.setHelpAvailable(false);
        dialog.open();
    }
    return null;
}

From source file:com.bb.extensions.plugin.unittests.internal.handlers.UninstallUnitTestsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IProject project = null;//from  w w  w  .  jav  a 2 s.  co m

    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
    if (selection != null & selection instanceof IStructuredSelection) {
        IStructuredSelection strucSelection = (IStructuredSelection) selection;
        project = (IProject) strucSelection.getFirstElement();
    }

    int style = SWT.ICON_WARNING | SWT.YES | SWT.NO | SWT.CANCEL;

    MessageBox messageBox = new MessageBox(workbenchWindow.getShell(), style);
    messageBox.setMessage("The Unit Tests will be deleted from the workspace.\n "
            + "Do you want the unit tests to be deleted from the file system as well ?");
    int rc = messageBox.open();

    if (rc == SWT.CANCEL) {
        return null;
    }

    if (project != null) {
        Job job = new UninstallUnitTestsJob(project, rc == SWT.YES);
        job.setUser(true);
        job.schedule();
    }
    return null;
}

From source file:com.bdaum.juploadr.uploadapi.smugrest.ui.AlbumPolicyDialog.java

License:Open Source License

@Override
protected void okPressed() {
    saveValues();//from w w  w. java 2  s .c om
    session.setAlbumPolicy(albumGroup.getSelection() == 0 ? SmugmugRestApi.SELECT : SmugmugRestApi.USEDEFAULT);
    IStructuredSelection selection = viewer.getStructuredSelection();
    if (!selection.isEmpty())
        session.setDefaultAlbum(((PhotoSet) selection.getFirstElement()));
    super.okPressed();
}

From source file:com.bdaum.juploadr.uploadapi.smugrest.ui.AlbumPolicyDialog.java

License:Open Source License

private void saveValues() {
    CommunityAccount account = session.getAccount();
    account.setAlbumPolicy(albumGroup.getSelection() == 0 ? SmugmugRestApi.SELECT : SmugmugRestApi.USEDEFAULT);
    IStructuredSelection selection = viewer.getStructuredSelection();
    if (!selection.isEmpty())
        account.setDefaultAlbum(((PhotoSet) selection.getFirstElement()).getTitle());
    account.save();//  w  ww. j  a v a  2  s.  co m
}

From source file:com.bdaum.zoom.gps.internal.views.MapView.java

License:Open Source License

public void setMaptype(String maptype) {
    IStructuredSelection sel = comboContributionItem.getSelection();
    if (!sel.isEmpty())
        GpsActivator.setCurrentMapType((IConfigurationElement) sel.getFirstElement(), maptype);
}

From source file:com.bdaum.zoom.net.communities.CommunitiesPreferencePage.java

License:Open Source License

@SuppressWarnings("unused")
public Control createPageContents(final Composite parent, AbstractPreferencePage parentPage) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));
    ((GridLayout) composite.getLayout()).verticalSpacing = 0;
    new Label(composite, SWT.NONE).setText(Messages.CommunitiesPreferencePage_community_descr);
    ExpandCollapseGroup expandCollapseGroup = new ExpandCollapseGroup(composite, SWT.NONE);
    CGroup group = createGroup(composite, 2, Messages.CommunitiesPreferencePage_photo_community_accounts);
    accountViewer = new TreeViewer(group, SWT.V_SCROLL | SWT.SINGLE | SWT.BORDER);
    expandCollapseGroup.setViewer(accountViewer);
    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.heightHint = 200;/*  www. ja v a 2s . c  o m*/
    accountViewer.getControl().setLayoutData(layoutData);
    accountViewer.setContentProvider(new AccountContentProvider(accounts));
    accountViewer.setLabelProvider(new AccountLabelProvider(accountViewer));
    accountViewer.setComparator(ZViewerComparator.INSTANCE);
    UiUtilities.installDoubleClickExpansion(accountViewer);
    Composite buttonGroup = new Composite(group, SWT.NONE);
    buttonGroup.setLayoutData(new GridData(SWT.END, SWT.FILL, false, true));
    buttonGroup.setLayout(new GridLayout(1, false));
    newButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_new,
            Messages.CommunitiesPreferencePage_create_a_new_account);
    newButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection();
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof IConfigurationElement) {
                IConfigurationElement conf = (IConfigurationElement) firstElement;
                CommunityApi communitiesApi = CommunitiesActivator.getCommunitiesApi(conf);
                String id = conf.getAttribute("id"); //$NON-NLS-1$
                List<CommunityAccount> list = accounts.get(id);
                IConfigurationElement config = conf.getChildren()[0];
                EditCommunityAccountDialog dialog = new EditCommunityAccountDialog(parent.getShell(),
                        new CommunityAccount(config), communitiesApi);
                if (dialog.open() == Window.OK) {
                    CommunityAccount result = dialog.getResult();
                    list.add(result);
                    setViewerInput();
                    accountViewer.setSelection(new StructuredSelection(result));
                }
            }
        }
    });

    editButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_edit,
            Messages.CommunitiesPreferencePage_edit_selected_account);
    editButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection();
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof CommunityAccount) {
                final CommunityAccount account = (CommunityAccount) firstElement;
                IConfigurationElement conf = (IConfigurationElement) account.getConfiguration().getParent();
                final CommunityApi communitiesApi = CommunitiesActivator.getCommunitiesApi(conf);
                BusyIndicator.showWhile(e.display, () -> {
                    EditCommunityAccountDialog dialog = new EditCommunityAccountDialog(parent.getShell(),
                            account, communitiesApi);
                    if (dialog.open() == Window.OK) {
                        CommunityAccount result = dialog.getResult();
                        accountViewer.update(result, null);
                        changed.add(result.getCommunityId());
                    }
                });
            }
        }
    });
    new Label(buttonGroup, SWT.SEPARATOR | SWT.HORIZONTAL);
    removeButton = createPushButton(buttonGroup, Messages.CommunitiesPreferencePage_remove,
            Messages.CommunitiesPreferencePage_remove_selected_account);
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection();

            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof CommunityAccount) {
                CommunityAccount communityAccount = (CommunityAccount) firstElement;
                List<CommunityAccount> acc = accounts.get(communityAccount.getCommunityId());
                if (acc != null) {
                    int i = acc.indexOf(communityAccount);
                    CommunityAccount sibling = (i < acc.size() - 1) ? acc.get(i + 1)
                            : (i > 0) ? acc.get(i - 1) : null;
                    acc.remove(i);
                    changed.add(communityAccount.getCommunityId());
                    setViewerInput();
                    if (sibling != null)
                        accountViewer.setSelection(new StructuredSelection(sibling));
                }
            }
        }
    });
    accountViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
            validate();
        }
    });
    setViewerInput();
    updateButtons();
    return composite;
}

From source file:com.bdaum.zoom.net.communities.CommunitiesPreferencePage.java

License:Open Source License

@Override
public void updateButtons() {
    IStructuredSelection selection = (IStructuredSelection) accountViewer.getSelection();
    boolean enabled = (selection.getFirstElement() instanceof CommunityAccount);
    editButton.setEnabled(enabled);//  www.ja v a2  s. c  o  m
    removeButton.setEnabled(enabled);
    boolean newenabled = (selection.getFirstElement() instanceof IConfigurationElement);
    newButton.setEnabled(newenabled);
}

From source file:com.bdaum.zoom.net.communities.ui.CommunityExportWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    setDialogSettings(Ui.getUi().getDialogSettings(settingsId));
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    AssetSelection assetSelection;/*w w w.j  ava 2 s  . c  o m*/
    assetSelection = activeWorkbenchWindow != null
            ? Ui.getUi().getNavigationHistory(activeWorkbenchWindow).getSelectedAssets()
            : (selection instanceof AssetSelection) ? ((AssetSelection) selection) : AssetSelection.EMPTY;
    assets = assetSelection.getAssets();
    if (assets.isEmpty()) {
        if (activeWorkbenchWindow != null) {
            IDbManager dbManager = Core.getCore().getDbManager();
            INavigationHistory navigationHistory = Ui.getUi().getNavigationHistory(activeWorkbenchWindow);
            IStructuredSelection sel = navigationHistory.getOtherSelection();
            if (sel != null) {
                Object first = sel.getFirstElement();
                if (first instanceof SlideShowImpl) {
                    SlideShowImpl show = (SlideShowImpl) first;
                    String name = show.getName();
                    AlbumDescriptor currentAlbum = new AlbumDescriptor(name, show.getDescription());
                    AomList<String> entries = show.getEntry();
                    assets = new ArrayList<Asset>(entries.size());
                    List<AlbumDescriptor> albums = new ArrayList<AlbumDescriptor>(entries.size());
                    List<String> titleList = new ArrayList<String>(entries.size());
                    List<String> descriptionList = new ArrayList<String>(entries.size());
                    for (String slideId : entries) {
                        SlideImpl slide = dbManager.obtainById(SlideImpl.class, slideId);
                        if (slide != null) {
                            String assetId = slide.getAsset();
                            if (assetId != null) {
                                AssetImpl asset = dbManager.obtainAsset(assetId);
                                if (asset != null) {
                                    assets.add(asset);
                                    albums.add(currentAlbum);
                                    titleList.add(slide.getCaption());
                                    descriptionList.add(slide.getDescription());
                                    currentAlbum.addTags(asset.getKeyword());
                                } else {
                                    currentAlbum = new AlbumDescriptor(name + ":" + slide.getCaption(), //$NON-NLS-1$
                                            slide.getDescription());
                                }
                            }
                        }
                    }
                    associatedAlbums = albums.toArray(new AlbumDescriptor[albums.size()]);
                    titles = titleList.toArray(new String[titleList.size()]);
                    descriptions = descriptionList.toArray(new String[descriptionList.size()]);
                } else if (first instanceof ExhibitionImpl) {
                    ExhibitionImpl show = (ExhibitionImpl) first;
                    String name = show.getName();
                    String description = show.getDescription();
                    assets = new ArrayList<Asset>();
                    List<AlbumDescriptor> albums = new ArrayList<AlbumDescriptor>();
                    List<String> titleList = new ArrayList<String>();
                    List<String> descriptionList = new ArrayList<String>();
                    for (Wall wall : show.getWall()) {
                        AlbumDescriptor currentAlbum = new AlbumDescriptor(name + ":" + wall.getLocation(), //$NON-NLS-1$
                                description);
                        AomList<String> exhibits = wall.getExhibit();
                        for (String exhibitId : exhibits) {
                            ExhibitImpl exhibit = dbManager.obtainById(ExhibitImpl.class, exhibitId);
                            if (exhibit != null) {
                                String assetId = exhibit.getAsset();
                                if (assetId != null) {
                                    AssetImpl asset = dbManager.obtainAsset(assetId);
                                    if (asset != null) {
                                        assets.add(asset);
                                        albums.add(currentAlbum);
                                        titleList.add(exhibit.getTitle());
                                        descriptionList.add(exhibit.getDescription());
                                        currentAlbum.addTags(asset.getKeyword());
                                    }
                                }
                            }
                        }
                    }
                    associatedAlbums = albums.toArray(new AlbumDescriptor[albums.size()]);
                    titles = titleList.toArray(new String[titleList.size()]);
                    descriptions = descriptionList.toArray(new String[descriptionList.size()]);
                } else if (first instanceof WebGalleryImpl) {
                    WebGalleryImpl show = (WebGalleryImpl) first;
                    String name = show.getName();
                    assets = new ArrayList<Asset>();
                    List<AlbumDescriptor> albums = new ArrayList<AlbumDescriptor>();
                    List<String> titleList = new ArrayList<String>();
                    List<String> descriptionList = new ArrayList<String>();
                    for (Storyboard storyboard : show.getStoryboard()) {
                        AlbumDescriptor currentAlbum = new AlbumDescriptor(name + ":" + storyboard.getTitle(), //$NON-NLS-1$
                                storyboard.getDescription());
                        currentAlbum.addTags(show.getKeyword());
                        AomList<String> exhibits = storyboard.getExhibit();
                        for (String exhibitId : exhibits) {
                            WebExhibitImpl exhibit = dbManager.obtainById(WebExhibitImpl.class, exhibitId);
                            if (exhibit != null) {
                                String assetId = exhibit.getAsset();
                                if (assetId != null) {
                                    AssetImpl asset = dbManager.obtainAsset(assetId);
                                    if (asset != null) {
                                        assets.add(asset);
                                        titleList.add(exhibit.getCaption());
                                        descriptionList.add(exhibit.getDescription());
                                        albums.add(currentAlbum);
                                        currentAlbum.addTags(asset.getKeyword());
                                    }
                                }
                            }
                        }
                    }
                    associatedAlbums = albums.toArray(new AlbumDescriptor[albums.size()]);
                    titles = titleList.toArray(new String[titleList.size()]);
                    descriptions = descriptionList.toArray(new String[descriptionList.size()]);
                }
            }
        }
    }
    List<Asset> filteredAssets = new ArrayList<Asset>(assets.size());
    for (Asset asset : assets)
        if (CoreActivator.getDefault().getMediaSupport(asset.getFormat()) == null)
            filteredAssets.add(asset);
    assets = filteredAssets;
    int size = assets.size();
    setWindowTitle(size == 0 ? Messages.CommunityExportWizard_nothing_selected
            : size == 1 ? NLS.bind(Messages.CommunityExportWizard_export_one_image, communityName)
                    : NLS.bind(Messages.CommunityExportWizard_export_n_images, communityName, size));
}

From source file:com.bdaum.zoom.net.communities.ui.ExportToCommunityPage.java

License:Open Source License

@Override
protected void updateFields() {
    super.updateFields();
    IStructuredSelection sel = accountViewer.getStructuredSelection();
    if (!sel.isEmpty()) {
        CommunityAccount account = (CommunityAccount) sel.getFirstElement();
        boolean noOrigs = !account.isSupportsRaw() && hasRawImaages;
        if (noOrigs) {
            exportModeGroup.setOriginalsEnabled(false);
            setMessage(msg + Messages.ExportToCommunityPage_cannot_send_orginals);
        } else/*from  www.j a  va  2s  .  c  o m*/
            setMessage(msg);
    }
    validatePage();
}