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.preferences.ImportPreferencePage.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from ww  w  .  j ava 2  s  . co  m
protected void doFillValues() {
    BatchActivator batch = BatchActivator.getDefault();
    IRawConverter rc = batch.getCurrentRawConverter(false);
    previousRawConverter = rc;
    IPreferenceStore preferenceStore = getPreferenceStore();
    Map<String, IRawConverter> rawConverters = batch.getRawConverters();
    if (rc != null)
        rcViewer.setSelection(new StructuredSelection(rc));
    for (IRawConverter c : rawConverters.values()) {
        FileEditor fileEditor = basicsFileEditors.get(c.getId());
        if (fileEditor != null) {
            String path = preferenceStore.getString(c.getPathId());
            if (path.isEmpty()) {
                String editorName = c.getName();
                if (editorName != null) {
                    FileEditorMapping editorMapping = null;
                    for (String rf : ImageConstants.getRawFormatMap().keySet()) {
                        editorMapping = UiActivator.getDefault().getFileEditorMapping(rf);
                        if (editorMapping != null)
                            break;
                    }
                    if (editorMapping != null)
                        for (EditorDescriptor editorDescriptor : editorMapping.getEditors())
                            if (editorName.equalsIgnoreCase(editorDescriptor.getLabel())) {
                                path = editorDescriptor.getFileName();
                                break;
                            }
                }
            }
            fileEditor.setText(path);
        }
        for (IRawConverter.RawProperty prop : c.getProperties()) {
            prop.value = preferenceStore.getString(prop.id);
            Object object = optionProps.get(prop.id);
            if (object instanceof ComboViewer) {
                ComboViewer viewer = (ComboViewer) object;
                for (RawEnum rawEnum : (List<RawEnum>) viewer.getInput())
                    if (rawEnum.id.equals(prop.value)) {
                        viewer.setSelection(new StructuredSelection(rawEnum));
                        if (rawEnum.recipe) {
                            c.setUsesRecipes(rawEnum.id);
                            if (c == rc)
                                previousUsesRecipes = rawEnum.id;
                        }
                        break;
                    }
            } else if (object instanceof Spinner)
                try {
                    ((Spinner) object).setSelection(Integer.parseInt(prop.value));
                } catch (NumberFormatException e) {
                    // do nothing
                }
            else if (object instanceof Button)
                ((Button) object).setSelection(Boolean.parseBoolean(prop.value));
            else if (object instanceof Text)
                ((Text) object).setText(prop.value);
        }
    }
    if (modeviewer != null)
        modeviewer.setSelection(
                new StructuredSelection(preferenceStore.getString(PreferenceConstants.RAWIMPORT)));
    if (dngpathEditor != null)
        dngpathEditor.setText(preferenceStore.getString(PreferenceConstants.DNGCONVERTERPATH));
    if (uncompressedButton != null)
        uncompressedButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.DNGUNCOMPRESSED));
    if (linearButton != null)
        linearButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.DNGLINEAR));
    if (dngfolderField != null)
        dngfolderField.setText(preferenceStore.getString(PreferenceConstants.DNGFOLDER));
    maxSpinner.setSelection(preferenceStore.getInt(PreferenceConstants.MAXIMPORTS));
    String s = preferenceStore.getString(PreferenceConstants.DEVICEWATCH);
    deviceGroup.setSelection(PreferenceConstants.TETHERED.equals(s) ? 2 : Boolean.parseBoolean(s) ? 1 : 0);
    int tetheredShow = preferenceStore.getInt(PreferenceConstants.TETHEREDSHOW);
    tetheredGroup.setSelection(tetheredShow);
    showButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWIMPORTED));
    makerNotesButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.IMPORTMAKERNOTES));
    faceDataButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.IMPORTFACEDATA));
    if (recipeViewer != null) {
        List<String> configurations = Core.fromStringList(
                preferenceStore.getString(PreferenceConstants.RECIPEDETECTORCONFIGURATIONS), "\n"); //$NON-NLS-1$
        if (configurations != null && allDetectors != null)
            for (String conf : configurations) {
                int p = conf.indexOf(':');
                if (p > 0) {
                    String id = conf.substring(0, p);
                    for (IRecipeDetector detector : allDetectors) {
                        if (detector.getId().equals(id)) {
                            StringTokenizer st = new StringTokenizer(conf.substring(p + 1), ";"); //$NON-NLS-1$
                            while (st.hasMoreTokens()) {
                                String parm = st.nextToken();
                                int q = parm.indexOf('=');
                                if (q > 0) {
                                    IRecipeParameter parameter = detector.getParameter(parm.substring(0, q));
                                    if (parameter != null)
                                        parameter.setValue(parm.substring(q + 1));
                                }
                            }
                            break;
                        }
                    }
                }
            }
        selectedRecipeDetectors = Core
                .fromStringList(preferenceStore.getString(PreferenceConstants.RECIPEDETECTORS), "\n"); //$NON-NLS-1$
        previousRecipeDetectors = new HashSet<String>(selectedRecipeDetectors);
        recipeViewer.setInput(allDetectors);
        previousProcessRecipes = preferenceStore.getBoolean(PreferenceConstants.PROCESSRECIPES);
        processRecipesButton.setSelection(previousProcessRecipes);
        archiveRecipesButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ARCHIVERECIPES));
    }
    deviceGroup.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            checkForTetheringHint();
        }
    });
}

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

private void createConflictsArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout(1, false));
    new Label(composite, SWT.NONE).setText(Messages.getString("KeyPreferencePage.conflicts")); //$NON-NLS-1$
    conflictViewer = new TableViewer(composite,
            SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    Table table = conflictViewer.getTable();
    TableViewerColumn bindingNameColumn = new TableViewerColumn(conflictViewer, SWT.LEAD);
    bindingNameColumn.getColumn().setWidth(250);
    table.setLayoutData(new GridData(250, 80));
    bindingNameColumn.setLabelProvider(new ZColumnLabelProvider() {
        @Override/*from  w w w  .  j  a  va  2s.  co m*/
        public String getText(Object element) {
            if (element instanceof Binding[]) {
                StringBuilder sb = new StringBuilder();
                for (Binding binding : ((Binding[]) element)) {
                    ParameterizedCommand parameterizedCommand = binding.getParameterizedCommand();
                    String s = Messages.getString("KeyPreferencePage.undefined"); //$NON-NLS-1$
                    if (parameterizedCommand != null)
                        try {
                            s = parameterizedCommand.getName();
                        } catch (NotDefinedException e) {
                            // do nothing
                        }
                    if (sb.length() > 0)
                        sb.append("; "); //$NON-NLS-1$
                    sb.append(s);
                }
                return sb.toString();
            }
            return element.toString();
        }
    });
    conflictViewer.setContentProvider(ArrayContentProvider.getInstance());
    conflictViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (!selection.isEmpty()) {
                Binding[] conflict = (Binding[]) selection.getFirstElement();
                bindingViewer.setSelection(new StructuredSelection(conflict[0]));
            }
        }
    });
}

From source file:com.bdaum.zoom.ui.internal.preferences.KeyPreferencePage.java

License:Open Source License

@Override
protected void fillValues() {
    IBindingService bindingService = PlatformUI.getWorkbench().getService(IBindingService.class);
    userMap.clear();// ww w .j ava  2s. c o m
    systemMap.clear();
    commandMap.clear();
    activeSchemeId = bindingService.getActiveScheme().getId();
    Binding[] bindings = bindingService.getBindings();
    for (Binding binding : bindings) {
        if (activeSchemeId.equals(binding.getSchemeId())) {
            TriggerSequence triggerSequence = binding.getTriggerSequence();
            if (binding.getType() == Binding.SYSTEM)
                systemMap.put(triggerSequence, binding);
            else
                userMap.put(triggerSequence, binding);
        }
    }
    updateViewer();
    ISelection selection = bindingViewer.getSelection();
    if (selection.isEmpty())
        bindingViewer.setSelection(new StructuredSelection(bindingViewer.getElementAt(0)), true);
}

From source file:com.bdaum.zoom.ui.internal.views.AbstractGalleryView.java

License:Open Source License

@Override
protected void makeActions(IActionBars bars) {
    super.makeActions(bars);
    saveQueryAction = new Action(Messages.getString("AbstractGalleryView.save_query_as_collection"), //$NON-NLS-1$
            Icons.tableSave.getDescriptor()) {
        @Override//from  w w  w .  j  a  v  a  2 s  .c  o  m
        public void run() {
            IAssetProvider assetProvider = getAssetProvider();
            final SmartCollectionImpl currentCollection = assetProvider == null ? null
                    : assetProvider.getCurrentCollection();
            if (currentCollection != null && currentCollection.getAdhoc()) {
                final SmartCollection parent = currentCollection.getSmartCollection_subSelection_parent();
                ZInputDialog dialog = new ZInputDialog(getSite().getShell(),
                        parent != null
                                ? NLS.bind(Messages.getString("AbstractGalleryView.save_as_subcollection"), //$NON-NLS-1$
                                        parent.getName())
                                : Messages.getString("AbstractGalleryView.save_as_collection"), //$NON-NLS-1$
                        Messages.getString("AbstractGalleryView.collection_name"), currentCollection.getName(), //$NON-NLS-1$
                        new IInputValidator() {

                            public String isValid(String newText) {
                                if (newText != null && !newText.isEmpty())
                                    return null;
                                return Messages.getString("AbstractGalleryView.please_specify_a_name"); //$NON-NLS-1$
                            }
                        }, false);
                if (dialog.open() == Window.OK) {
                    String name = dialog.getValue();
                    currentCollection.setName(name);
                    currentCollection.setAdhoc(false);
                    final IDbManager dbManager = Core.getCore().getDbManager();
                    dbManager.safeTransaction(() -> {
                        if (parent != null) {
                            parent.addSubSelection(currentCollection);
                            dbManager.store(parent);
                        } else {
                            GroupImpl user = UiUtilities.obtainUserGroup(dbManager);
                            user.addRootCollection(currentCollection.getStringId());
                            currentCollection.setGroup_rootCollection_parent(user.getStringId());
                            dbManager.store(user);
                        }
                        dbManager.store(currentCollection);
                    });
                    try {
                        CatalogView catalogView = (CatalogView) getSite().getPage().showView(CatalogView.ID);
                        catalogView.refresh();
                        catalogView.setSelection(new StructuredSelection(currentCollection));
                    } catch (PartInitException e) {
                        // should never happen
                    }
                    updateActions(false);
                }
            }
        }
    };
    saveQueryAction.setToolTipText(Messages.getString("AbstractGalleryView.adds_the_current_query")); //$NON-NLS-1$
    removeFromAlbumAction = addAction(ZoomActionFactory.REMOVEFROMALBUM.create(bars, this));
    selectRatingAction = new Action(Messages.getString("AbstractGalleryView.show_all_images"), //$NON-NLS-1$
            Icons.ratingAll.getDescriptor()) {

        @Override
        public void runWithEvent(Event event) {
            IRatingFilter oldFilter = null;
            IAssetFilter[] filters = getNavigationHistory().getFilters();
            int rating = QueryField.SELECTALL;
            if (filters != null)
                for (IAssetFilter filter : filters) {
                    if (filter instanceof IRatingFilter) {
                        oldFilter = ((IRatingFilter) filter);
                        rating = oldFilter.getRating();
                        break;
                    }
                }
            RatingDialog dialog = new RatingDialog(getSite().getShell(), rating);
            dialog.create();
            Widget widget = event.widget;
            if (widget instanceof ToolItem) {
                Rectangle bounds = ((ToolItem) widget).getBounds();
                dialog.getShell().setLocation(
                        ((ToolItem) widget).getParent().toDisplay(bounds.x, bounds.y + bounds.height));
            }
            int newRating = dialog.open();
            if (newRating != RatingDialog.SELECTABORT && (newRating != rating)) {
                IRatingFilter newFilter = newRating != QueryField.SELECTALL
                        ? Core.getCore().getDbFactory().createRatingFilter(newRating)
                        : null;
                getNavigationHistory().updateFilters(oldFilter, newFilter);
                String tooltip = newRating <= 0 ? null
                        : NLS.bind(Messages.getString("AbstractGalleryView.show_only_image_or_better"), //$NON-NLS-1$
                                QueryField.RATING.getEnumLabels()[newRating + 1]);
                Icon icon;
                switch (newRating) {
                case QueryField.SELECTALL:
                    tooltip = Messages.getString("AbstractGalleryView.show_all_images"); //$NON-NLS-1$
                    icon = Icons.ratingAll;
                    break;
                case 0:
                    icon = Icons.rating0;
                    break;
                case 1:
                    icon = Icons.rating1;
                    break;
                case 2:
                    icon = Icons.rating2;
                    break;
                case 3:
                    icon = Icons.rating3;
                    break;
                case 4:
                    icon = Icons.rating4;
                    break;
                case 5:
                    icon = Icons.rating5;
                    break;
                default:
                    tooltip = Messages.getString("AbstractGalleryView.show_unrated_images"); //$NON-NLS-1$
                    icon = Icons.rating_undef;
                    break;
                }
                setToolTipText(tooltip);
                setImageDescriptor(icon.getDescriptor());
            }
        }
    };
    selectRatingAction.setToolTipText(Messages.getString("AbstractGalleryView.show_images_with_rating")); //$NON-NLS-1$

    selectColorCodeAction = new Action(Messages.getString("AbstractGalleryView.indepent_of_color_code"), //$NON-NLS-1$
            Icons.dashed.getDescriptor()) {

        @Override
        public void runWithEvent(Event event) {
            IColorCodeFilter oldFilter = null;
            IAssetFilter[] filters = getNavigationHistory().getFilters();
            int colorCode = QueryField.SELECTALL;
            if (filters != null)
                for (IAssetFilter filter : filters) {
                    if (filter instanceof IColorCodeFilter) {
                        oldFilter = ((IColorCodeFilter) filter);
                        colorCode = oldFilter.getColorCode();
                        break;
                    }
                }
            ColorCodeDialog dialog = new ColorCodeDialog(getSite().getShell(), colorCode);
            dialog.create();
            Widget widget = event.widget;
            if (widget instanceof ToolItem) {
                Rectangle bounds = ((ToolItem) widget).getBounds();
                dialog.getShell().setLocation(
                        ((ToolItem) widget).getParent().toDisplay(bounds.x, bounds.y + bounds.height));
            }
            int newColorCode = dialog.open();
            if (newColorCode != ColorCodeDialog.SELECTABORT && (newColorCode != colorCode)) {
                IColorCodeFilter newFilter = newColorCode != Constants.COLOR_UNDEFINED
                        ? Core.getCore().getDbFactory().createColorCodeFilter(newColorCode)
                        : null;
                getNavigationHistory().updateFilters(oldFilter, newFilter);
                String tooltip = newColorCode <= 0 ? null
                        : NLS.bind(Messages.getString("AbstractGalleryView.with_color_code"), //$NON-NLS-1$
                                QueryField.COLORCODELABELS[newColorCode + 1]);
                Icon icon;
                switch (newColorCode) {
                case Constants.COLOR_BLACK:
                    icon = Icons.black;
                    break;
                case Constants.COLOR_WHITE:
                    icon = Icons.white;
                    break;
                case Constants.COLOR_RED:
                    icon = Icons.red;
                    break;
                case Constants.COLOR_GREEN:
                    icon = Icons.green;
                    break;
                case Constants.COLOR_BLUE:
                    icon = Icons.blue;
                    break;
                case Constants.COLOR_CYAN:
                    icon = Icons.cyan;
                    break;
                case Constants.COLOR_MAGENTA:
                    icon = Icons.magenta;
                    break;
                case Constants.COLOR_YELLOW:
                    icon = Icons.yellow;
                    break;
                case Constants.COLOR_ORANGE:
                    icon = Icons.orange;
                    break;
                case Constants.COLOR_PINK:
                    icon = Icons.pink;
                    break;
                case Constants.COLOR_VIOLET:
                    icon = Icons.violet;
                    break;
                default:
                    tooltip = Messages.getString("AbstractGalleryView.indepent_of_color_code"); //$NON-NLS-1$
                    icon = Icons.dashed;
                    break;
                }
                setToolTipText(tooltip);
                setImageDescriptor(icon.getDescriptor());
            }
        }
    };
    selectColorCodeAction.setToolTipText(Messages.getString("AbstractGalleryView.with_selected_color_code")); //$NON-NLS-1$

    selectFileTypeAction = new Action(Messages.getString("AbstractGalleryView.select_file_type"), //$NON-NLS-1$
            Icons.format.getDescriptor()) {

        @Override
        public void runWithEvent(Event event) {
            int formats = ITypeFilter.ALLFORMATS;
            ITypeFilter oldFilter = null;
            IAssetFilter[] filters = getNavigationHistory().getFilters();
            if (filters != null)
                for (IAssetFilter filter : filters)
                    if (filter instanceof ITypeFilter) {
                        oldFilter = ((ITypeFilter) filter);
                        formats = oldFilter.getFormats();
                        break;
                    }
            FileFormatDialog dialog = new FileFormatDialog(getSite().getShell(), formats);
            dialog.create();
            Widget widget = event.widget;
            if (widget instanceof ToolItem) {
                Rectangle bounds = ((ToolItem) widget).getBounds();
                dialog.getShell().setLocation(
                        ((ToolItem) widget).getParent().toDisplay(bounds.x, bounds.y + bounds.height));
            }
            int newFormats = dialog.open();
            if (newFormats >= 0 && newFormats != formats) {
                ITypeFilter newFilter = newFormats == ITypeFilter.ALLFORMATS ? null
                        : Core.getCore().getDbFactory().createTypeFilter(newFormats);
                getNavigationHistory().updateFilters(oldFilter, newFilter);
                String tooltip;
                Icon icon;
                if (newFormats == ITypeFilter.ALLFORMATS) {
                    tooltip = Messages.getString("AbstractGalleryView.show_all_images_independent_of_format"); //$NON-NLS-1$
                    icon = Icons.format;
                } else {
                    icon = Icons.formatSelect;
                    StringBuffer sb = new StringBuffer();
                    if ((newFormats & ITypeFilter.RAW) != 0)
                        sb.append("Raw"); //$NON-NLS-1$
                    if ((newFormats & ITypeFilter.DNG) != 0) {
                        if (sb.length() > 0)
                            sb.append(", "); //$NON-NLS-1$
                        sb.append("DNG"); //$NON-NLS-1$
                    }
                    if ((newFormats & ITypeFilter.JPEG) != 0) {
                        if (sb.length() > 0)
                            sb.append(", "); //$NON-NLS-1$
                        sb.append("JPEG"); //$NON-NLS-1$
                    }
                    if ((newFormats & ITypeFilter.TIFF) != 0) {
                        if (sb.length() > 0)
                            sb.append(", "); //$NON-NLS-1$
                        sb.append("TIFF"); //$NON-NLS-1$
                    }
                    if ((newFormats & ITypeFilter.OTHER) != 0) {
                        if (sb.length() > 0)
                            sb.append(", "); //$NON-NLS-1$
                        sb.append(Messages.getString("AbstractGalleryView.Other")); //$NON-NLS-1$
                    }
                    if ((newFormats & ITypeFilter.MEDIA) != 0) {
                        if (sb.length() > 0)
                            sb.append(", "); //$NON-NLS-1$
                        sb.append(Messages.getString("AbstractGalleryView.other_media")); //$NON-NLS-1$
                    }
                    tooltip = NLS.bind(
                            Messages.getString("AbstractGalleryView.show_only_images_with_selected_formats"), //$NON-NLS-1$
                            sb);
                }
                setToolTipText(tooltip);
                setImageDescriptor(icon.getDescriptor());
            }
        }
    };
    selectFileTypeAction
            .setToolTipText(Messages.getString("AbstractGalleryView.show_all_images_independent_of_format")); //$NON-NLS-1$

    retargetAction = new Action(Messages.getString("AbstractGalleryView.retarget")) { //$NON-NLS-1$
        @Override
        public void runWithEvent(Event event) {
            AssetSelection sel = (AssetSelection) getSelection();
            AssetImpl asset = (AssetImpl) sel.getFirstElement();
            URI uri = Core.getCore().getVolumeManager().findFile(asset);
            File file = new File(uri);
            DirectoryDialog dialog = new DirectoryDialog(getSite().getShell());
            dialog.setText(Messages.getString("AbstractGalleryView.retarget_title")); //$NON-NLS-1$
            dialog.setFilterPath(file.getParent());
            String oldPath = file.getPath();
            String folderPath = dialog.open();
            if (folderPath != null) {
                File folder = new File(folderPath);
                File newFile = new File(folder, file.getName());
                if (!newFile.exists()) {
                    List<File> files = new ArrayList<File>();
                    collectFiles(folder, file.getName(), files);
                    if (files.isEmpty()) {
                        AcousticMessageDialog.openInformation(getSite().getShell(),
                                Messages.getString("AbstractGalleryView.retarget_title"), //$NON-NLS-1$
                                NLS.bind(Messages.getString("AbstractGalleryView.target_file_not_found"), //$NON-NLS-1$
                                        file.getName(), folder));
                        return;
                    }
                    SelectTargetDialog selectDialog = new SelectTargetDialog(getSite().getShell(), files,
                            folder);
                    if (selectDialog.open() != SelectTargetDialog.OK)
                        return;
                    newFile = selectDialog.getFile();
                }
                if (newFile.getName().equals(file.getName())) {
                    RetargetDialog retargetDialog = new RetargetDialog(getSite().getShell(), oldPath,
                            newFile.getAbsolutePath());
                    if (retargetDialog.open() == RetargetDialog.OK)
                        OperationJob
                                .executeOperation(
                                        new RetargetOperation(asset, newFile, retargetDialog.getResult(),
                                                retargetDialog.getRetargetVoiceNote()),
                                        AbstractGalleryView.this);
                } else
                    AcousticMessageDialog.openInformation(getSite().getShell(),
                            Messages.getString("AbstractGalleryView.retarget_impossible"), //$NON-NLS-1$
                            Messages.getString("AbstractGalleryView.file_names_do_not_match")); //$NON-NLS-1$
            }
        }

        private void collectFiles(File folder, String name, List<File> files) {
            File[] members = folder.listFiles();
            if (members != null)
                for (File file : members)
                    if (file.isDirectory())
                        collectFiles(file, name, files);
                    else if (file.getName().equals(name))
                        files.add(file);
        }
    };
    retargetAction.setToolTipText(Messages.getString("AbstractGalleryView.retarget_tooltip")); //$NON-NLS-1$
    renameAction = addAction(ZoomActionFactory.BULKRENAME.create(bars, this));
    stackAction = addAction(ZoomActionFactory.STACK.create(bars, this));
    splitCatAction = addAction(ZoomActionFactory.SPLITCATALOG.create(null, this));
    selectionActionCluster = ZoomActionFactory.createSelectionActionCluster(this, this);
}

From source file:com.bdaum.zoom.ui.internal.views.AbstractGalleryView.java

License:Open Source License

@Override
public void refresh() {
    redrawCollection(null, null);/*from   ww w .j a  v a  2  s . c  o  m*/
    if (initialSelection != null) {
        IAssetProvider assetProvider = getAssetProvider();
        if (assetProvider != null) {
            SmartCollectionImpl coll = assetProvider.loadCollection(initialSelection);
            if (coll != null)
                Ui.getUi().getNavigationHistory(getSite().getWorkbenchWindow())
                        .selectionChanged(new SelectionChangedEvent(this, new StructuredSelection(coll)));
            initialSelection = null;
        }
    }
}

From source file:com.bdaum.zoom.ui.internal.views.AbstractPropertiesView.java

License:Open Source License

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *///from w w  w .  j  av a2  s. c o  m

@SuppressWarnings("unused")
@Override
public void createPartControl(Composite parent) {
    computeFlags();
    if (essentials == null) {
        essentials = new HashSet<QueryField>(100);
        computeEssentials();
    }
    preferenceListener = new IPreferenceChangeListener() {
        public void preferenceChange(PreferenceChangeEvent event) {
            if (PreferenceConstants.ESSENTIALMETADATA.equals(event.getKey())) {
                computeEssentials();
                refreshInternal();
            }
        }
    };
    InstanceScope.INSTANCE.getNode(UiActivator.PLUGIN_ID).addPreferenceChangeListener(preferenceListener);
    viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    int[] colWidth = getColumnWidths();
    TreeViewerColumn col1 = new TreeViewerColumn(viewer, SWT.NONE);
    final Tree tree = viewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    final ViewEditingSupport editingSupport = new ViewEditingSupport(viewer);
    col1.getColumn().setWidth(colWidth[0]);
    col1.getColumn().setText(Messages.getString("AbstractPropertiesView.Name")); //$NON-NLS-1$
    col1.setLabelProvider(new MetadataLabelProvider() {
        @Override
        public String getText(Object element) {
            return (editingSupport.canEdit(element)) ? Format.EDITABLEINDICATOR + super.getText(element)
                    : super.getText(element);
        }
    });
    TreeViewerColumn col2 = new TreeViewerColumn(viewer, SWT.NONE);
    col2.getColumn().setWidth(colWidth[1]);
    col2.getColumn().setText(Messages.getString("AbstractPropertiesView.Value")); //$NON-NLS-1$
    col2.setLabelProvider(new ValueColumnLabelProvider());
    col2.setEditingSupport(editingSupport);
    TreeViewerColumn col3 = new TreeViewerColumn(viewer, SWT.NONE);
    col3.getColumn().setWidth(colWidth[2]);
    col3.setLabelProvider(new ActionColumnLabelProvider());
    viewer.setContentProvider(new MetadataContentProvider());
    viewer.setComparator(ZViewerComparator.INSTANCE);
    viewer.setFilters(new ViewerFilter[] { new DetailsViewerFilter(), new ContentTypeViewerFilter() });
    ZColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setInput(getRootElement());
    parent.getDisplay().asyncExec(() -> {
        if (!parent.isDisposed()) {
            if (expandedElements != null) {
                List<QueryField> elements = new ArrayList<QueryField>();
                StringTokenizer st = new StringTokenizer(expandedElements);
                while (st.hasMoreTokens()) {
                    QueryField qf1 = QueryField.findQueryField(st.nextToken());
                    if (qf1 != null)
                        elements.add(qf1);
                }
                viewer.setExpandedElements(elements.toArray());
                expandedElements = null;
            } else
                viewer.expandToLevel(getExpandLevel());
            if (selectedElement != null) {
                QueryField qf2 = QueryField.findQueryField(selectedElement);
                if (qf2 != null)
                    viewer.setSelection(new StructuredSelection(qf2), true);
                selectedElement = null;
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateActions(false);
        }
    });
    UiUtilities.installDoubleClickExpansion(viewer);
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {
            int col = -1;
            int x = e.x;
            for (int i = 0; i < 3; i++) {
                int w = tree.getColumn(i).getWidth();
                if (x < w) {
                    col = i;
                    break;
                }
                x -= w;
            }
            if (col == 2) {
                TreeItem item = tree.getItem(new Point(e.x, e.y));
                Object element = item.getData();
                if (element instanceof QueryField) {
                    QueryField qfield = (QueryField) element;
                    if (qfield.getAction() != QueryField.ACTION_NONE)
                        processAction(qfield, (e.stateMask & SWT.SHIFT) != 0);
                } else if (element instanceof TrackRecord) {
                    String visit = ((TrackRecord) element).getVisit();
                    if (visit != null)
                        showWebUrl(visit);
                }
            }
        }
    });
    new ColumnLayoutManager(viewer, getColumnWidths(), getColumnMaxWidths());
    addKeyListener();
    addGestureListener(tree);
    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), HelpContextIds.METADATA_VIEW);
    makeActions();
    installListeners();
    hookContextMenu();
    contributeToActionBars();
    final QueryField.Visitor qfVisitor = new QueryField.Visitor() {
        @Override
        public void doVisitorWork(QueryField node) {
            viewer.refresh(node);
        }
    };
    Core.getCore().addCatalogListener(new CatalogAdapter() {
        @Override
        public void assetsModified(BagChange<Asset> changes, final QueryField node) {
            for (Asset asset : getNavigationHistory().getSelectedAssets()) {
                if (changes == null || changes.hasChanged(asset)) {
                    Shell shell = getSite().getShell();
                    if (shell != null && !shell.isDisposed())
                        shell.getDisplay().asyncExec(() -> {
                            if (!tree.isDisposed()) {
                                resetCaches();
                                if (node != null)
                                    viewer.expandToLevel(node, qfVisitor.visit(node));
                                else
                                    refresh();
                            }
                        });
                    break;
                }
            }
        }
    });
    updateActions(false);
}

From source file:com.bdaum.zoom.ui.internal.views.AbstractPropertiesView.java

License:Open Source License

protected void processAction(QueryField qfield, boolean shift) {
    switch (qfield.getAction()) {
    case QueryField.ACTION_QUERY:
        Object fieldValue = getFieldValue(qfield);
        SmartCollection sm = createAdhocQuery(qfield, fieldValue, shift);
        getNavigationHistory().postSelection(new StructuredSelection(sm));
        break;// www .j av  a  2 s.  co  m
    case QueryField.ACTION_TOFOLDER:
        Asset asset = getNavigationHistory().getSelectedAssets().getFirstElement();
        sm = Utilities.obtainFolderCollection(Core.getCore().getDbManager(), asset.getUri(), asset.getVolume());
        if (sm != null) {
            try {
                ((CatalogView) getSite().getPage().showView(CatalogView.ID))
                        .setSelection(new StructuredSelection(sm), true);
            } catch (PartInitException e1) {
                // should never happen
            }
        }
        break;
    case QueryField.ACTION_MAP:
        ILocationDisplay locationDisplay = UiActivator.getDefault().getLocationDisplay();
        if (locationDisplay != null) {
            Object lat = getFieldValue(QueryField.EXIF_GPSLATITUDE);
            Object lon = getFieldValue(QueryField.EXIF_GPSLONGITUDE);
            if (lat instanceof Double && lon instanceof Double) {
                double latitude = ((Double) lat).doubleValue();
                double longitude = ((Double) lon).doubleValue();
                if (!Double.isNaN(latitude) && !Double.isNaN(longitude)) {
                    LocationImpl loc = new LocationImpl();
                    loc.setLatitude(latitude);
                    loc.setLongitude(longitude);
                    locationDisplay.display(loc);
                }
            }
        }
        break;
    case QueryField.ACTION_WWW:
        fieldValue = getFieldValue(qfield);
        showWebUrl((String) fieldValue);
        break;
    case QueryField.ACTION_EMAIL:
        fieldValue = getFieldValue(qfield);
        sendMail(fieldValue);
        break;
    }
}

From source file:com.bdaum.zoom.ui.internal.views.AssetDragSourceListener.java

License:Open Source License

public void dragSetData(DragSourceEvent event) {
    if (fileTransfer.isSupportedType(event.dataType)) {
        ICore core = Core.getCore();//w  w w .jav  a 2  s.c  o  m
        IVolumeManager volumeManager = core.getVolumeManager();
        List<String> files = new ArrayList<String>(assetSelection.size());
        for (Asset asset : assetSelection) {
            URI uri = volumeManager.findFile(asset);
            if (uri != null && Constants.FILESCHEME.equals(uri.getScheme())) {
                String absolutePath = (new File(uri)).getAbsolutePath();
                if (volumeManager.findExistingFile(asset, true) != null)
                    files.add(absolutePath);
                else {
                    String volume = asset.getVolume();
                    if (volume != null && !volume.isEmpty())
                        volumes.add(volume);
                    errands.add(absolutePath);
                }
            }
        }
        event.data = files.toArray(new String[files.size()]);
    } else if (textTransfer.isSupportedType(event.dataType)) {
        StringBuilder sb = new StringBuilder();
        for (Asset asset : assetSelection) {
            if (sb.length() > 0)
                sb.append('\n');
            sb.append(asset.getStringId());
        }
        event.data = sb.toString();
    } else if (selectionTransfer.isSupportedType(event.dataType))
        selectionTransfer.setSelection(region != null ? new StructuredSelection(region) : assetSelection);
}

From source file:com.bdaum.zoom.ui.internal.views.BasicView.java

License:Open Source License

public void postSelection(Object object) {
    getNavigationHistory();/*from   w  w  w  . j ava  2s .  com*/
    if (navigationHistory != null)
        navigationHistory.postSelection(new StructuredSelection(object));
}

From source file:com.bdaum.zoom.ui.internal.views.BookmarkView.java

License:Open Source License

private void makeActions() {
    gotoBookmarkAction = new GotoBookmarkAction(null, this);
    deleteAction = new Action(Messages.getString("BookmarkView.delete_bookmark"), Icons.delete //$NON-NLS-1$
            .getDescriptor()) {/*from w  w  w  .ja v  a2  s . co  m*/
        @Override
        public void run() {
            IStructuredSelection selection = viewer.getStructuredSelection();
            if (!selection.isEmpty()) {
                Bookmark bookmark = (Bookmark) selection.getFirstElement();
                Core.getCore().getDbManager().safeTransaction(bookmark, null);
                int i = 0;
                while (true) {
                    Object element = viewer.getElementAt(i++);
                    if (element == null || element == bookmark)
                        break;
                }
                Object nextSelection = viewer.getElementAt(i);
                if (nextSelection == null && i >= 2)
                    nextSelection = viewer.getElementAt(i - 2);
                viewer.remove(bookmark);
                if (nextSelection != null)
                    viewer.setSelection(new StructuredSelection(nextSelection));
                updateActions();
            }
        }
    };
    deleteAction.setToolTipText(Messages.getString("BookmarkView.delete_bookmark_tooltip")); //$NON-NLS-1$
}