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.bdaum.zoom.ui.internal.actions.ProximityAction.java

License:Open Source License

@Override
public void run() {
    AssetSelection selection = adaptable.getAdapter(AssetSelection.class);
    double lat = 0;
    double lon = 0;
    int n = 0;/*ww  w  . ja  v  a2 s.  com*/
    for (Asset asset : selection)
        if (!Double.isNaN(asset.getGPSLatitude()) && !Double.isNaN(asset.getGPSLongitude())) {
            lat += asset.getGPSLatitude();
            double longitude = asset.getGPSLongitude();
            if (lon < 0 && longitude > 0)
                longitude -= 360;
            else if (lon > 0 && longitude < 0)
                longitude += 360;
            lon += longitude;
            n++;
        }
    if (n == 0) {
        AcousticMessageDialog.openInformation(shell, Messages.ProximityAction_proximity_search,
                Messages.ProximityAction_no_geotagged_image);
        return;
    }
    ProximityDialog dialog = new ProximityDialog(shell);
    if (dialog.open() == Window.OK) {
        double distance = dialog.getResult();
        lat /= n;
        lon /= n;
        double mx = 0;
        char unit = Core.getCore().getDbFactory().getDistanceUnit();
        for (Asset asset : selection)
            if (!Double.isNaN(asset.getGPSLatitude()) && !Double.isNaN(asset.getGPSLongitude()))
                mx = Math.max(mx,
                        Core.distance(lat, lon, asset.getGPSLatitude(), asset.getGPSLongitude(), unit));
        Object[] values = new Object[] { lat, lon, (distance + mx), unit };
        SmartCollectionImpl coll = new SmartCollectionImpl(Messages.ProximityAction_proximity_search, false,
                false, true, dialog.isNetworked(), null, 0, null, 0, null, Constants.INHERIT_LABEL, null, 0,
                null);
        coll.addCriterion(new CriterionImpl(QueryField.EXIF_GPSLOCATIONDISTANCE.getKey(), null, values,
                QueryField.NOTGREATER, false));
        coll.addSortCriterion(new SortCriterionImpl(QueryField.EXIF_GPSLOCATIONDISTANCE.getKey(), null, false));
        coll.setSmartCollection_subSelection_parent(dialog.getParentCollection());
        Ui.getUi().getNavigationHistory(adaptable.getAdapter(IWorkbenchWindow.class))
                .postSelection(new StructuredSelection(coll));
    }
}

From source file:com.bdaum.zoom.ui.internal.actions.TimeSearchAction.java

License:Open Source License

@Override
public void run() {
    Date date1 = new Date(Long.MAX_VALUE);
    Date date2 = new Date(0);
    List<Asset> selectedAssets = adaptable.getAdapter(AssetSelection.class).getAssets();
    if (!selectedAssets.isEmpty())
        for (Asset asset : selectedAssets) {
            Date date = asset.getDateTimeOriginal();
            if (date == null)
                date = asset.getDateTime();
            if (date != null) {
                if (date1.compareTo(date) > 0)
                    date1 = date;/*from   w  ww.j  a va  2s .  c  o m*/
                if (date2.compareTo(date) < 0)
                    date2 = date;
            }
        }
    if (date1.compareTo(date2) > 0) {
        date1 = new Date();
        date2 = new Date();
    }
    TimeSearchDialog dialog = new TimeSearchDialog(adaptable.getAdapter(Shell.class), date1, date2);
    if (dialog.open() == Window.OK)
        Ui.getUi().getNavigationHistory(adaptable.getAdapter(IWorkbenchWindow.class))
                .postSelection(new StructuredSelection(dialog.getResult()));
}

From source file:com.bdaum.zoom.ui.internal.actions.ZoomActionFactory.java

License:Open Source License

private static void showInGallery(final IAdaptable adaptable, final Asset asset, SmartCollection sm) {
    if (sm != null) {
        try {/*from ww w . j  a  v  a2 s.  co m*/
            IViewPart gallery = null;
            BasicView currentView = adaptable.getAdapter(BasicView.class);
            IWorkbenchPage page = adaptable.getAdapter(IWorkbenchPage.class);
            if (currentView instanceof LightboxView && !(currentView instanceof TrashcanView)
                    || currentView instanceof ZuiView || currentView instanceof TableView)
                gallery = currentView;
            else {
                for (IViewReference ref : page.getViewReferences()) {
                    String id = ref.getId();
                    if (id.equals(LightboxView.ID) || id.equals(ZuiView.ID) || id.equals(TableView.ID)
                            || id.equals(LightboxView.VSTRIPVIEW) || id.equals(LightboxView.HSTRIPVIEW)) {
                        if (currentView == null || !id.equals(currentView.getViewSite().getId())) {
                            IViewPart view = page.findView(id);
                            if (view instanceof AbstractGalleryView
                                    && ((AbstractGalleryView) view).isVisible()) {
                                gallery = page.showView(id);
                                break;
                            }
                        }
                    }
                }
                if (gallery == null
                        && (currentView == null || !LightboxView.ID.equals(currentView.getViewSite().getId())))
                    gallery = page.showView(LightboxView.ID);
            }
            ((CatalogView) page.showView(CatalogView.ID)).setSelection(new StructuredSelection(sm), true);
            INavigationHistory navigationHistory = Ui.getUi().getNavigationHistory(page.getWorkbenchWindow());
            navigationHistory.postSelection(AssetSelection.EMPTY);
            navigationHistory.postSelection(new AssetSelection(asset));
            if (gallery != null)
                gallery.setFocus();
        } catch (PartInitException e) {
            // should never happen
        }
    }
}

From source file:com.bdaum.zoom.ui.internal.commands.AdhocQueryCommand.java

License:Open Source License

@Override
public void run() {
    UiActivator activator = UiActivator.getDefault();
    CollectionEditDialog dialog = new CollectionEditDialog(getShell(), activator.getLastAdhocQuery(),
            Messages.AdhocAction_adhoc_query, Messages.AdhocQueryCommand_edit_collection_msg, true, false,
            false, Core.getCore().isNetworked());
    if (dialog.open() == Window.OK) {
        final SmartCollectionImpl coll = dialog.getResult();
        activator.setLastAdhocQuery(coll);
        BusyIndicator.showWhile(getShell().getDisplay(), () -> Ui.getUi()
                .getNavigationHistory(getActiveWorkbenchWindow()).postSelection(new StructuredSelection(coll)));
    }//from  w  ww  .  ja v a  2  s  .  co m
}

From source file:com.bdaum.zoom.ui.internal.commands.KeywordQueryCommand.java

License:Open Source License

@Override
public void run() {
    KeywordSearchDialog dialog = new KeywordSearchDialog(getShell(), null);
    if (dialog.open() == Window.OK)
        Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow())
                .postSelection(new StructuredSelection(dialog.getResult()));
}

From source file:com.bdaum.zoom.ui.internal.commands.LastImportCommand.java

License:Open Source License

@Override
public void run() {
    SmartCollectionImpl sm = Core.getCore().getDbManager().obtainById(SmartCollectionImpl.class,
            Constants.LAST_IMPORT_ID);//w ww. j  a  v  a2 s  . c o  m
    if (sm != null)
        Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow()).postSelection(new StructuredSelection(sm));
}

From source file:com.bdaum.zoom.ui.internal.commands.OrphansCommand.java

License:Open Source License

@Override
public void run() {
    AcousticMessageDialog includeDialog = new AcousticMessageDialog(getShell(),
            Messages.FindOrphansActionDelegate_search_orphans, null,
            Messages.FindOrphansActionDelegate_include_off_line, AcousticMessageDialog.QUESTION, new String[] {
                    IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
            1);//from   w  w w  .j ava  2  s .c  om
    final int ret = includeDialog.open();
    if (ret >= 2)
        return;
    isCanceled = false;
    ZProgressMonitorDialog dialog = new ZProgressMonitorDialog(getShell());
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ICore core = Core.getCore();
            IVolumeManager volumeManager = core.getVolumeManager();
            List<AssetImpl> set = core.getDbManager().obtainAssets();
            monitor.beginTask(Messages.FindOrphansActionDelegate_scanning_catalog, set.size());
            for (AssetImpl asset : set) {
                URI uri = volumeManager.findExistingFile(asset, false);
                if (uri == null) {
                    if (ret == 0 || !volumeManager.isOffline(asset.getVolume()))
                        result.add(asset);
                    else {
                        String volume = asset.getVolume();
                        if (volume != null && !volume.isEmpty())
                            volumes.add(volume);
                    }
                }
                if (monitor.isCanceled()) {
                    isCanceled = true;
                    break;
                }
                monitor.worked(1);
            }
            monitor.done();
        }
    };
    if (isCanceled)
        return;
    try {
        String v = null;
        if (!volumes.isEmpty()) {
            String[] vols = volumes.toArray(new String[volumes.size()]);
            Arrays.sort(vols);
            StringBuffer sb = new StringBuffer();
            for (String volume : vols) {
                if (sb.length() > 0)
                    sb.append(", "); //$NON-NLS-1$
                sb.append(volume);
            }
            v = sb.toString();
        }
        dialog.run(true, true, runnable);
        if (result.isEmpty()) {
            String message = Messages.FindOrphansActionDelegate_no_orphans_found;
            if (ret == 1 && v != null)
                message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v);
            AcousticMessageDialog.openInformation(getShell(), Messages.FindOrphansActionDelegate_orphan_search,
                    message);
        } else {
            boolean show = true;
            if (v != null) {
                String message = NLS.bind(Messages.FindOrphansActionDelegate_n_entries_found, result.size());
                if (ret == 1)
                    message += NLS.bind(Messages.FindOrphansActionDelegate_entries_not_checked, v);
                show = AcousticMessageDialog.openConfirm(getShell(),
                        Messages.FindOrphansActionDelegate_orphan_search, message);
            }
            if (show) {
                SmartCollectionImpl collection = new SmartCollectionImpl(
                        Messages.FindOrphansActionDelegate_orphans, true, false, true, false, null, 0, null, 0,
                        null, Constants.INHERIT_LABEL, null, 0, null);
                collection.addCriterion(
                        new CriterionImpl(ICollectionProcessor.ORPHANS, null, result, QueryField.XREF, false));
                Ui.getUi().getNavigationHistory(getActiveWorkbenchWindow())
                        .postSelection(new StructuredSelection(collection));
            }
        }
    } catch (InvocationTargetException e) {
        UiActivator.getDefault().logError(Messages.FindOrphansActionDelegate_error_scanning_for_orphans, e);
    } catch (InterruptedException e) {
        // nothing to do
    }
}

From source file:com.bdaum.zoom.ui.internal.commands.QuickFindControl.java

License:Open Source License

private void performSearch(boolean shift) {
    String text = inputField.getText().trim();
    if (text.isEmpty() || shift || !validate(text)) {
        if (fullSearchActivated())
            Core.getCore().getDbFactory().getLireService(true).performQuery(text, this,
                    ICollectionProcessor.TEXTSEARCH);
        else {/*from   www.  j  a v  a  2  s  . c  o m*/
            KeywordSearchDialog dialog = new KeywordSearchDialog(getWorkbenchWindow().getShell(), text);
            if (dialog.open() == Window.OK)
                Ui.getUi().getNavigationHistory(getWorkbenchWindow())
                        .postSelection(new StructuredSelection(dialog.getResult()));
        }
    } else {
        SmartCollection sm;
        if (fullSearchActivated()) {
            QueryOptions queryOptions = UiActivator.getDefault().getQueryOptions();
            sm = new SmartCollectionImpl(
                    text + NLS.bind(Messages.QuickFindControl_maxmin, queryOptions.getMaxHits(),
                            queryOptions.getScore()),
                    false, false, true, queryOptions.isNetworked(), null, 0, null, 0, null,
                    Constants.INHERIT_LABEL, null, 0, null);
            sm.addCriterion(new CriterionImpl(ICollectionProcessor.TEXTSEARCH, null,
                    new TextSearchOptions_typeImpl(text, queryOptions.getMaxHits(),
                            queryOptions.getScore() / 100f),
                    Constants.TEXTSEARCHOPTIONS_DEFAULT_MIN_SCORE, false));
        } else
            sm = KeywordSearchDialog.computeQuery(text, false, null);
        Ui.getUi().getNavigationHistory(getWorkbenchWindow()).postSelection(new StructuredSelection(sm));
    }
}

From source file:com.bdaum.zoom.ui.internal.commands.QuickFindControl.java

License:Open Source License

protected void addDropSupport(final Control control) {
    final int ops = DND.DROP_MOVE | DND.DROP_COPY;
    final DropTarget target = new DropTarget(control, ops);
    final TextTransfer textTransfer = TextTransfer.getInstance();
    Transfer[] types = new Transfer[] { textTransfer };
    target.setTransfer(types);/*from   w ww.  j  a v a2  s  .  c o  m*/
    target.addDropListener(new EffectDropTargetListener(control) {
        @Override
        public void dragEnter(DropTargetEvent event) {
            int detail = event.detail;
            event.detail = DND.DROP_NONE;
            if (fullSearchActivated()) {
                for (int i = 0; i < event.dataTypes.length; i++) {
                    if (textTransfer.isSupportedType(event.dataTypes[i])) {
                        event.currentDataType = event.dataTypes[i];
                        if ((detail & ops) != 0) {
                            event.detail = DND.DROP_COPY;
                            break;
                        }
                    }
                }
            }
            super.dragEnter(event);
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
            event.detail = fullSearchActivated() ? DND.DROP_NONE
                    : textTransfer.isSupportedType(event.currentDataType)
                            ? (event.detail & ops) == 0 ? DND.DROP_NONE : DND.DROP_COPY
                            : DND.DROP_NONE;
        }

        @Override
        public void drop(DropTargetEvent event) {
            if (fullSearchActivated() && textTransfer.isSupportedType(event.currentDataType)) {
                String ids = (String) event.data;
                StringTokenizer st = new StringTokenizer(ids, "\n"); //$NON-NLS-1$
                if (st.hasMoreTokens()) {
                    String id = st.nextToken();
                    IDbManager dbManager = Core.getCore().getDbManager();
                    AssetImpl asset = dbManager.obtainAsset(id);
                    if (asset != null) {
                        QueryOptions queryOptions = UiActivator.getDefault().getQueryOptions();
                        int method = queryOptions.getMethod();
                        int validMethod = -1;
                        Set<String> cbirAlgorithms = CoreActivator.getDefault().getCbirAlgorithms();
                        Algorithm algorithm = Core.getCore().getDbFactory().getLireService(true)
                                .getAlgorithmById(method);
                        if (algorithm != null && cbirAlgorithms.contains(algorithm.getName()))
                            validMethod = method;
                        if (validMethod < 0 && configureSearch())
                            validMethod = queryOptions.getMethod();
                        if (validMethod >= 0) {
                            SimilarityOptions_typeImpl newOptions = new SimilarityOptions_typeImpl(validMethod,
                                    queryOptions.getMaxHits(), queryOptions.getScore() / 100f, 0, 1, 10, 30, id,
                                    queryOptions.getKeywordWeight());
                            String[] keywords = asset.getKeyword();
                            if (queryOptions.getKeywordWeight() > 0 && keywords != null && keywords.length > 0)
                                newOptions.setKeywords(Arrays.copyOf(keywords, keywords.length));
                            else
                                newOptions.setKeywordWeight(0);
                            if (queryOptions.getKeywordWeight() < 100)
                                newOptions.setPngImage(asset.getJpegThumbnail());
                            SmartCollectionImpl collection = new SmartCollectionImpl(
                                    NLS.bind(Messages.QuickFindControl_images_similar, asset.getName()), false,
                                    false, true, queryOptions.isNetworked(), null, 0, null, 0, null,
                                    Constants.INHERIT_LABEL, null, 0, null);
                            collection.addCriterion(new CriterionImpl(ICollectionProcessor.SIMILARITY, null,
                                    newOptions, queryOptions.getScore(), false));
                            Ui.getUi().getNavigationHistory(getWorkbenchWindow())
                                    .postSelection(new StructuredSelection(collection));
                        }
                    }
                }
            }
        }
    });
}

From source file:com.bdaum.zoom.ui.internal.dialogs.AbstractSelectExhibitDialog.java

License:Open Source License

public void setSelection(Object obj) {
    viewer.setSelection(new StructuredSelection(obj), true);
}