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

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

Introduction

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

Prototype

public TreeViewer(Composite parent, int style) 

Source Link

Document

Creates a tree viewer on a newly-created tree control under the given parent.

Usage

From source file:com.arm.cmsis.pack.widgets.RteDeviceSelectorWidget.java

License:Apache License

/**
 * Create the composite./*from   w  w w  . ja v  a 2 s. c om*/
 * @param parent
 * @param style
 */
public RteDeviceSelectorWidget(Composite parent, int style) {
    super(parent, SWT.NONE);

    contentLabelProvider = new RteDeviceTreeContentProvider();
    GridLayout gridLayout = new GridLayout(6, false);
    gridLayout.horizontalSpacing = 8;
    setLayout(gridLayout);

    Label lblDeviceLabel = new Label(this, SWT.NONE);
    lblDeviceLabel.setText("Device:");

    lblDevice = new Label(this, SWT.NONE);
    lblDevice.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(this, SWT.NONE);

    Label lblCpuLabel = new Label(this, SWT.NONE);
    lblCpuLabel.setText("CPU:");
    lblCpuLabel.setBounds(0, 0, 36, 13);

    lblCpu = new Label(this, SWT.NONE);
    lblCpu.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    lblCpu.setBounds(0, 0, 32, 13);
    new Label(this, SWT.NONE);

    Label lblVendorLabel = new Label(this, SWT.NONE);
    lblVendorLabel.setText("Vendor:");

    lblVendor = new Label(this, SWT.NONE);
    lblVendor.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(this, SWT.NONE);

    Label lblFpuLabel = new Label(this, SWT.NONE);
    lblFpuLabel.setText("FPU:");
    lblFpuLabel.setBounds(0, 0, 38, 13);

    comboFpu = new Combo(this, SWT.READ_ONLY);
    comboFpu.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (updatingControls)
                return;
            int index = comboFpu.getSelectionIndex();
            selectedFpu = fpuIndexToString(index);
        }
    });
    comboFpu.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(this, SWT.NONE);

    Label lblSearch = new Label(this, SWT.NONE);
    lblSearch.setText("Search:");

    txtSearch = new Text(this, SWT.BORDER);
    txtSearch.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            setSearchText(txtSearch.getText());
        }
    });
    txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtSearch.setToolTipText("Enter search mask to filter device tree");
    new Label(this, SWT.NONE);

    Label lblEndian = new Label(this, SWT.NONE);
    lblEndian.setText("Endian:");
    lblEndian.setBounds(0, 0, 37, 13);

    comboEndian = new Combo(this, SWT.READ_ONLY);
    comboEndian.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (updatingControls)
                return;
            selectedEndian = adjustEndianString(comboEndian.getText());
        }
    });
    comboEndian.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(this, SWT.NONE);

    treeViewer = new TreeViewer(this, SWT.BORDER);
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            handleTreeSelectionChanged(event);
        }
    });
    Tree tree = treeViewer.getTree();
    GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd_tree.minimumWidth = 240;
    tree.setLayoutData(gd_tree);

    treeViewer.setContentProvider(contentLabelProvider);
    treeViewer.setLabelProvider(contentLabelProvider);
    treeViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (fSearchString.isEmpty() || fSearchString.equals("*")) {
                return true;
            }
            if (element instanceof IRteDeviceItem) {
                String s = fSearchString;
                if (!s.endsWith("*"))
                    s += "*";
                IRteDeviceItem deviceItem = (IRteDeviceItem) element;
                return deviceItem.getFirstItem(s) != null;
            }
            return false;
        }

    });

    text = new Text(this, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    GridData gd_text = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd_text.widthHint = 240;
    gd_text.minimumWidth = 200;
    text.setLayoutData(gd_text);
    text.setEditable(false);

    setTabList(new Control[] { txtSearch, tree, comboFpu, comboEndian });

    addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            fSelectedItem = null;
            contentLabelProvider = null;
            fDevices = null;
            listeners.clear();
            listeners = null;
        }
    });

}

From source file:com.astra.ses.spell.gui.views.NavigationView.java

License:Open Source License

/***********************************************************************
 * Create the view contents.//w ww  .  j a  v  a 2  s.  co m
 * 
 * @param parent The top composite of the view
 **********************************************************************/
public void createPartControl(Composite parent) {
    Logger.debug("Created", Level.INIT, this);

    FillLayout layout = (FillLayout) parent.getLayout();
    layout.spacing = 5;
    layout.type = SWT.VERTICAL;

    m_proceduresManager = new ProceduresStructureManager();
    m_proceduresManager.setView(this);
    m_procTree = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    // Set the providers
    m_procTree.setContentProvider(new ProcedureListContentProvider());
    m_procTree.setLabelProvider(new ProcedureListLabelProvider());
    m_procTree.setSorter(new NodeSorter());
    // Set the procedure manager as the model provider
    m_procTree.setInput(m_proceduresManager.getRootElements());
    // Register the navigation view in the selection service
    getSite().setSelectionProvider(m_procTree);
    // Register this view as open listener as well
    m_procTree.addOpenListener(this);
    m_procTree.addSelectionChangedListener(this);
    // Register the view as a service listener for the procedure manager
    // in order to receive updates when the list of available procedures
    // may have changed.
    ViewManager vmgr = (ViewManager) ServiceManager.get(ViewManager.ID);
    vmgr.registerView(ID, this);
}

From source file:com.astra.ses.spell.gui.views.StackView.java

License:Open Source License

/***********************************************************************
 * Create the view contents./*  ww w  .  j  a v a2s .  co  m*/
 * 
 * @param parent The top composite of the view
 **********************************************************************/
public void createPartControl(Composite parent) {
    Logger.debug("Created", Level.INIT, this);
    // Create the viewer control
    m_viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    // Set the providers
    m_viewer.setContentProvider(new StackViewContentProvider());
    m_viewer.setLabelProvider(new StackViewLabelProvider());
    // Set the procedure manager as the model provider
    StackModel model = new StackModel(this);

    m_viewer.setInput(model.getModelData());
    // Register the navigation view in the selection service
    getSite().setSelectionProvider(m_viewer);
    // Register the view as a service listener for the procedure manager
    // in order to receive updates when the list of available procedures
    // may have changed.
    ViewManager vmgr = (ViewManager) ServiceManager.get(ViewManager.ID);
    vmgr.registerView(ID, this);
}

From source file:com.baremetalstudios.mapleide.internal.ResourceNavigator.java

License:Open Source License

@Inject
public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) {
    final Realm realm = SWTObservables.getRealm(parent.getDisplay());
    this.context = context;
    parent.setLayout(new FillLayout());
    TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            selectionService/*w  w w .  j  av a2  s  .co  m*/
                    .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
            //            context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });

    IObservableFactory setFactory = new IObservableFactory() {
        public IObservable createObservable(Object element) {
            if (element instanceof IContainer && ((IContainer) element).exists()) {
                IObservableSet observableSet = observableSets.get(element);
                if (observableSet == null) {
                    observableSet = new WritableSet(realm);
                    try {
                        observableSet.addAll(Arrays.asList(((IContainer) element).members()));
                    } catch (CoreException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    observableSets.put((IContainer) element, observableSet);
                }
                return observableSet;
            }
            return Observables.emptyObservableSet();
        }
    };
    viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() {
        public Boolean hasChildren(Object element) {
            return Boolean.valueOf(element instanceof IContainer);
        }
    }));

    viewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof IResource)
                return ((IResource) element).getName();
            return element == null ? "" : element.toString();
        }
    });
    viewer.setSorter(new ViewerSorter());
    viewer.setInput(workspace.getRoot());
    viewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {

            MapleIDEApplication app = (MapleIDEApplication) application;
            IStructuredSelection s = (IStructuredSelection) event.getSelection();
            for (Object o : s.toArray()) {
                if (o instanceof IFile) {
                    IFile f = (IFile) o;
                    context.set(IFile.class, f);
                    String fExt = f.getFileExtension();
                    EDITOR: for (EditorPartDescriptor desc : app.getEditorPartDescriptors()) {
                        for (String ext : desc.getFileextensions()) {
                            if (ext.equals(fExt)) {
                                context.set(EditorPartDescriptor.class, desc);
                                System.err.println("Opening with: " + desc);

                                Command cmd = commandService
                                        .getCommand("com.baremetalstudios.mapleide.command.openeditor");
                                //                           Command cmd = commandService.getCommand("simpleide.command.openeditor");
                                ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null);
                                handlerService.executeHandler(pCmd);

                                break EDITOR;
                            }
                        }
                    }
                }
            }

        }
    });
    setupContextMenu(viewer, parent.getShell());
    workspace.addResourceChangeListener(listener);
}

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;//ww w . j  a v a2s .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.peer.internal.preferences.PeerPreferencePage.java

License:Open Source License

@SuppressWarnings("unused")
private Control createSharedGroup(CTabFolder parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    comp.setLayout(new GridLayout());
    Composite innerComp = new Composite(comp, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;//from w ww.ja v  a2 s . c  o m
    layout.marginHeight = 20;
    innerComp.setLayout(layout);
    innerComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Label label = new Label(innerComp, SWT.WRAP);
    label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1));
    label.setText(Messages.PeerPreferencePage_shared_cats_msg);

    catViewer = new TreeViewer(innerComp, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    catViewer.getTree().setLinesVisible(true);
    catViewer.getTree().setHeaderVisible(true);
    catViewer.getTree().setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, true));
    TreeViewerColumn col1 = new TreeViewerColumn(catViewer, SWT.NONE);
    col1.getColumn().setWidth(400);
    col1.getColumn().setText(Messages.PeerPreferencePage_path);
    col1.setLabelProvider(ZColumnLabelProvider.getDefaultInstance());
    TreeViewerColumn col2 = new TreeViewerColumn(catViewer, SWT.NONE);
    col2.getColumn().setWidth(200);
    col2.getColumn().setText(Messages.PeerPreferencePage_privacy);
    col2.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SharedCatalog)
                return translatePrivacy(((SharedCatalog) element).getPrivacy());
            if (element instanceof PeerDefinition)
                return ((PeerDefinition) element).getRightsLabel();
            return ""; //$NON-NLS-1$
        }
    });
    col1.setEditingSupport(new EditingSupport(catViewer) {
        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof PeerDefinition && value instanceof PeerDefinition) {
                ((PeerDefinition) element).setHost(((PeerDefinition) value).getHost());
                ((PeerDefinition) element).setPort(((PeerDefinition) value).getPort());
                catViewer.update(element, null);
                validate();
            }
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof PeerDefinition)
                return element;
            return null;
        }

        @Override
        protected CellEditor getCellEditor(final Object element) {
            if (element instanceof PeerDefinition) {
                return new DialogCellEditor(catViewer.getTree()) {
                    @Override
                    protected Object openDialogBox(Control cellEditorWindow) {
                        PeerDefinitionDialog dialog = new PeerDefinitionDialog(cellEditorWindow.getShell(),
                                (PeerDefinition) element, true, true, true);
                        if (dialog.open() == Window.OK)
                            return dialog.getResult();
                        return null;
                    }
                };
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            return (element instanceof PeerDefinition);
        }
    });
    col2.setEditingSupport(new EditingSupport(catViewer) {
        @Override
        protected void setValue(Object element, Object value) {
            if (element instanceof SharedCatalog && value instanceof Integer) {
                ((SharedCatalog) element).setPrivacy((Integer) value);
                catViewer.update(element, null);
            } else if (element instanceof PeerDefinition && value instanceof PeerDefinition) {
                ((PeerDefinition) element).setRights(((PeerDefinition) value).getRights());
                catViewer.update(element, null);
            }
        }

        @Override
        protected Object getValue(Object element) {
            if (element instanceof SharedCatalog)
                return ((SharedCatalog) element).getPrivacy();
            if (element instanceof PeerDefinition)
                return element;
            return null;
        }

        @Override
        protected CellEditor getCellEditor(final Object element) {
            if (element instanceof SharedCatalog) {
                ComboBoxViewerCellEditor editor = new ComboBoxViewerCellEditor(catViewer.getTree());
                editor.setLabelProvider(new LabelProvider() {
                    @Override
                    public String getText(Object element) {
                        return translatePrivacy(((Integer) element));
                    }
                });
                editor.setContentProvider(ArrayContentProvider.getInstance());
                editor.setInput(((SharedCatalog) element).getRestrictions().isEmpty()
                        ? new Integer[] { QueryField.SAFETY_RESTRICTED, QueryField.SAFETY_MODERATE,
                                QueryField.SAFETY_SAFE, QueryField.SAFETY_LOCAL }
                        : new Integer[] { QueryField.SAFETY_RESTRICTED, QueryField.SAFETY_MODERATE,
                                QueryField.SAFETY_SAFE });
                return editor;
            }
            if (element instanceof PeerDefinition) {
                return new DialogCellEditor(catViewer.getTree()) {
                    @Override
                    protected Object openDialogBox(Control cellEditorWindow) {
                        PeerDefinitionDialog dialog = new PeerDefinitionDialog(cellEditorWindow.getShell(),
                                (PeerDefinition) element, false, true, false);
                        if (dialog.open() == Window.OK)
                            return dialog.getResult();
                        return null;
                    }

                    @Override
                    protected void updateContents(Object value) {
                        if (value instanceof PeerDefinition)
                            super.updateContents(((PeerDefinition) value).getRightsLabel());
                    }
                };
            }
            return null;
        }

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }
    });
    catViewer.setContentProvider(new ITreeContentProvider() {

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // do nothing
        }

        public void dispose() {
            // do nothing
        }

        public boolean hasChildren(Object element) {
            if (element instanceof SharedCatalog)
                return !((SharedCatalog) element).getRestrictions().isEmpty();
            return false;
        }

        public Object getParent(Object element) {
            if (element instanceof PeerDefinition)
                return ((PeerDefinition) element).getParent();
            return null;
        }

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof Collection<?>)
                return ((Collection<?>) inputElement).toArray();
            return EMPTY;
        }

        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof SharedCatalog)
                return ((SharedCatalog) parentElement).getRestrictions().toArray();
            return EMPTY;
        }
    });
    new SortColumnManager(catViewer, new int[] { SWT.UP, SWT.NONE }, 0);
    catViewer.setComparator(ZViewerComparator.INSTANCE);
    UiUtilities.installDoubleClickExpansion(catViewer);
    Composite buttonGroup = new Composite(innerComp, SWT.NONE);
    buttonGroup.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, true));
    buttonGroup.setLayout(new GridLayout());
    addCurrentButton = new Button(buttonGroup, SWT.PUSH);
    addCurrentButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    addCurrentButton.setText(Messages.PeerPreferencePage_add_current);
    addCurrentButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String catFile = Core.getCore().getDbManager().getFileName();
            SharedCatalog cat = new SharedCatalog(catFile, QueryField.SAFETY_RESTRICTED);
            @SuppressWarnings("unchecked")
            List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput();
            catalogs.add(cat);
            catViewer.setInput(catalogs);
            catViewer.setSelection(new StructuredSelection(cat));
            updateButtons();
        }
    });

    final Button addButton = new Button(buttonGroup, SWT.PUSH);
    addButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    addButton.setText(Messages.PeerPreferencePage_add);
    addButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setFileName(Core.getCore().getDbManager().getFileName());
            String filename = dialog.open();
            if (filename != null) {
                SharedCatalog cat = new SharedCatalog(filename, QueryField.SAFETY_RESTRICTED);
                @SuppressWarnings("unchecked")
                List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput();
                catalogs.add(cat);
                catViewer.setInput(catalogs);
                catViewer.setSelection(new StructuredSelection(cat));
            }
        }
    });
    addRestrictionButton = new Button(buttonGroup, SWT.PUSH);
    addRestrictionButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    addRestrictionButton.setText(Messages.PeerPreferencePage_add_restriction);
    addRestrictionButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) catViewer.getSelection();
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof SharedCatalog) {
                PeerDefinitionDialog dialog = new PeerDefinitionDialog(getControl().getShell(), null, true,
                        true, true);
                if (dialog.open() == PeerDefinitionDialog.OK) {
                    PeerDefinition result = dialog.getResult();
                    result.setParent((SharedCatalog) firstElement);
                    catViewer.setInput(catViewer.getInput());
                    catViewer.expandToLevel(firstElement, 1);
                    catViewer.setSelection(new StructuredSelection(result));
                    validate();
                }
            }
        }
    });
    removeCatButton = new Button(buttonGroup, SWT.PUSH);
    removeCatButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    removeCatButton.setText(Messages.PeerPreferencePage_remove);
    removeCatButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) catViewer.getSelection();
            Object firstElement = sel.getFirstElement();
            if (firstElement instanceof SharedCatalog) {
                @SuppressWarnings("unchecked")
                List<SharedCatalog> catalogs = (List<SharedCatalog>) catViewer.getInput();
                catalogs.remove(firstElement);
                catViewer.setInput(catalogs);
                validate();
                updateButtons();
            }
        }
    });
    catViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });
    return comp;
}

From source file:com.bdaum.zoom.report.internal.wizards.SourcePage.java

License:Open Source License

@SuppressWarnings({ "unused" })
@Override//from w  w  w.  ja  v a  2s.c  o  m
public void createControl(Composite parent) {
    Composite composite = createComposite(parent, 3);
    setControl(composite);
    setHelp(HelpContextIds.REPORT_WIZARD);
    new Label(composite, SWT.NONE).setText(Messages.SourcePage_name);
    nameField = new Text(composite, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
    nameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    nameField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            report.setName(nameField.getText());
        }
    });
    browseButton = new Button(composite, SWT.PUSH);
    browseButton.setText(Messages.SourcePage_browse);
    browseButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ReportSelectionDialog dialog = new ReportSelectionDialog(getShell(), SWT.SINGLE);
            dialog.setInput(reports);
            if (dialog.open() == ReportSelectionDialog.OK) {
                Object[] result = dialog.getResult();
                if (result != null && result.length > 0) {
                    ((ReportWizard) getWizard()).setReport((Report) result[0]);
                    fillValues();
                    checkExistingReports();
                }
            }
        }
    });

    new Label(composite, SWT.NONE).setText(Messages.SourcePage_description);
    descriptionField = new CheckedText(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL,
            ISpellCheckingService.DESCRIPTIONOPTIONS);
    descriptionField.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            report.setDescription(descriptionField.getText());
        }
    });
    GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    layoutData.heightHint = 100;
    descriptionField.setLayoutData(layoutData);
    Composite sourceComp = new Composite(composite, SWT.NONE);
    sourceComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    sourceComp.setLayout(new GridLayout(1, false));
    sourceButtonGroup = new RadioButtonGroup(sourceComp, null, SWT.NONE, Messages.SourcePage_all,
            Messages.SourcePage_collection);
    sourceButtonGroup.addListener(this);
    sourceButtonGroup.setSelection(1);
    new Label(sourceComp, SWT.NONE);
    collViewer = new TreeViewer(sourceComp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    collViewer.setContentProvider(new CatalogContentProvider());
    collViewer.setLabelProvider(new CatalogLabelProvider(this));
    collViewer.setFilters(new ViewerFilter[] { collectionFilter });
    collViewer.setComparator(new CatalogComparator());
    UiUtilities.installDoubleClickExpansion(collViewer);
    setComparer();
    layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.widthHint = 300;
    layoutData.heightHint = 400;
    collViewer.getControl().setLayoutData(layoutData);
    collViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            validatePage();
        }
    });
    skipOrphansButton = WidgetFactory.createCheckButton(sourceComp, Messages.SourcePage_skip_orphans, null);
    setInput();
    updateFields();
    checkExistingReports();
    super.createControl(parent);
}

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

License:Open Source License

@SuppressWarnings("unused")
private void createTopicViewer(Composite composite) {
    ExpandCollapseGroup expandCollapseGroup = null;
    if (parser.hasSubtopics()) {
        expandCollapseGroup = new ExpandCollapseGroup(composite, SWT.NONE);
        TreeViewer treeViewer = new TreeViewer(composite,
                SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
        expandCollapseGroup.setViewer((TreeViewer) topicViewer);
        treeViewer.getTree().setLinesVisible(true);
        treeViewer.getTree().setHeaderVisible(true);
        if (!parser.isByName())
            createTreeColumn(treeViewer, 120, Messages.CodesDialog_code, 0);
        createTreeColumn(treeViewer, 150, Messages.CodesDialog_name, 1);
        createTreeColumn(treeViewer, 300, Messages.CodesDialog_explanation, 2);
        UiUtilities.installDoubleClickExpansion(treeViewer);
        topicViewer = treeViewer;//from   w  ww . j  a va2  s . c o m
    } else {
        new Label(composite, SWT.NONE);
        TableViewer tableViewer = new TableViewer(composite,
                SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
        tableViewer.getTable().setLinesVisible(true);
        tableViewer.getTable().setHeaderVisible(true);
        if (!parser.isByName())
            createTableColumn(tableViewer, 120, Messages.CodesDialog_code, 0);
        createTableColumn(tableViewer, 150, Messages.CodesDialog_name, 1);
        createTableColumn(tableViewer, 300, Messages.CodesDialog_explanation, 2);
        tableViewer.addDoubleClickListener(doubleClickListener);
        topicViewer = tableViewer;
    }
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    layoutData.heightHint = 300;
    topicViewer.getControl().setLayoutData(layoutData);
    topicViewer.setContentProvider(new TopicContentProvider());
    if (parser.isByName())
        new SortColumnManager(recentViewer, new int[] { SWT.UP, SWT.UP }, 0);
    else
        new SortColumnManager(recentViewer, new int[] { SWT.UP, SWT.UP, SWT.UP }, 1);
    topicViewer.setComparator(ZViewerComparator.INSTANCE);
    topicViewer.setFilters(new ViewerFilter[] { new TopicFilter(true, exclusions) });
    topicViewer.addSelectionChangedListener(selectionChangedListener);
    ZColumnViewerToolTipSupport.enableFor(topicViewer);
}

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

License:Open Source License

@SuppressWarnings("unused")
private TreeViewer createMetaDataGroup(Composite composite) {
    ExpandCollapseGroup expandCollapseGroup = new ExpandCollapseGroup(composite, SWT.NONE);
    new Label(composite, SWT.NONE);
    new Label(composite, SWT.NONE);
    final TreeViewer viewer = new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    expandCollapseGroup.setViewer(viewer);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    viewer.setLabelProvider(new MetadataLabelProvider());
    viewer.setContentProvider(new MetadataContentProvider());
    viewer.setComparator(ZViewerComparator.INSTANCE);
    UiUtilities.installDoubleClickExpansion(viewer);
    viewer.addFilter(new ViewerFilter() {
        @Override/*from  w  w w . j ava2  s .co m*/
        public boolean select(Viewer aViewer, Object parentElement, Object element) {
            if (element instanceof QueryField) {
                QueryField qfield = (QueryField) element;
                return qfield.hasChildren() || element != QueryField.EXIF_MAKERNOTES && qfield.isUiField()
                        && !columnFields.contains(element);
            }
            return false;
        }
    });
    viewer.setInput(QueryField.ALL);
    viewer.expandToLevel(2);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });
    return viewer;
}

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

License:Open Source License

@SuppressWarnings("unused")
private void createKeywordsGroup(final CTabFolder folder) {
    final Composite kwComp = createTabPage(folder, Messages.EditMetaDialog_keywords,
            Messages.EditMetaDialog_keyword_tooltip, 2, 0);
    CGroup kwGroup = new CGroup(kwComp, SWT.NONE);
    kwGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    kwGroup.setLayout(new GridLayout(2, false));
    kwGroup.setText(Messages.EditMetaDialog_cat_keywords);
    Label catKwLabel = new Label(kwGroup, SWT.NONE);
    catKwLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    catKwLabel.setFont(JFaceResources.getFontRegistry().get(UiConstants.SELECTIONFONT));
    flatKeywordGroup = new FlatGroup(kwGroup, SWT.NONE, settings, "hierarchicalKeywords"); //$NON-NLS-1$
    flatKeywordGroup.setLayoutData(new GridData(SWT.END, SWT.BEGINNING, false, false));
    flatKeywordGroup.addListener(new Listener() {
        @Override/*from   w  w w  . j ava  2s. c om*/
        public void handleEvent(Event event) {
            keywordViewer.setInput(keywords);
            keywordViewer.expandAll();
            keywordExpandCollapseGroup.setVisible(!flatKeywordGroup.isFlat());
        }
    });
    Composite viewerGroup = new Composite(kwGroup, SWT.NONE);
    viewerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layout = new GridLayout(2, false);
    layout.marginHeight = layout.marginWidth = 0;
    viewerGroup.setLayout(layout);
    final FilterField filterField = new FilterField(viewerGroup);
    filterField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            keywordViewer.setInput(keywords);
            keywordViewer.expandAll();
        }
    });
    final CheckboxButton excludeButton = WidgetFactory.createCheckButton(viewerGroup,
            Messages.KeywordGroup_exclude_geographic, new GridData(SWT.END, SWT.CENTER, true, false));
    excludeButton.addListener(new Listener() {

        @Override
        public void handleEvent(Event event) {
            excludeGeographic = excludeButton.getSelection();
            Object[] expandedElements = keywordViewer.getExpandedElements();
            keywordViewer.setInput(keywords);
            keywordViewer.setExpandedElements(expandedElements);
        }
    });
    keywordExpandCollapseGroup = new ExpandCollapseGroup(viewerGroup, SWT.NONE,
            new GridData(SWT.END, SWT.BEGINNING, true, false, 2, 1));
    keywordViewer = new TreeViewer(viewerGroup, SWT.V_SCROLL | SWT.BORDER);
    keywordExpandCollapseGroup.setViewer(keywordViewer);
    keywordExpandCollapseGroup.setVisible(!flatKeywordGroup.isFlat());
    setViewerLayout(keywordViewer, 220, 2);
    keywordViewer.setContentProvider(new KeywordContentProvider());
    keywordViewer.setLabelProvider(new KeywordLabelProvider(getVocabManager(), null));
    ZColumnViewerToolTipSupport.enableFor(keywordViewer);
    keywordViewer.setComparator(ZViewerComparator.INSTANCE);
    UiUtilities.installDoubleClickExpansion(keywordViewer);
    keywordViewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
        @Override
        public boolean select(Viewer aViewer, Object parentElement, Object element) {
            WildCardFilter filter = filterField.getFilter();
            return filter == null || element instanceof Character || filter.accept((String) element);
        }
    } });
    keywordViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });
    configureKeywordLink = new CLink(viewerGroup, SWT.NONE);
    configureKeywordLink.setText(Messages.EditMetaDialog_configure_keyword_filter);
    configureKeywordLink.addListener(new Listener() {
        @Override
        public void handleEvent(Event event) {
            PreferencesUtil.createPreferenceDialogOn(getShell(), KeyPreferencePage.ID, new String[0], null)
                    .open();
        }
    });
    final Composite buttonGroup = new Composite(kwGroup, SWT.NONE);
    buttonGroup.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    buttonGroup.setLayout(new GridLayout());

    keywordAddButton = createPushButton(buttonGroup, Messages.EditMetaDialog_add,
            Messages.EditMetaDialog_add_keyword_tooltip);
    keywordAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            ZInputDialog dialog = createKeywordDialog(Messages.EditMetaDialog_add_keyword,
                    Messages.EditMetaDialog_enter_a_new_keyword, ""); //$NON-NLS-1$
            if (dialog.open() == Window.OK)
                addKeywordToViewer(keywordViewer, dialog.getValue(), true);
        }
    });
    keywordModifyButton = createPushButton(buttonGroup, Messages.EditMetaDialog_edit,
            Messages.EditMetaDialog_modify_keyword_tooltip);
    keywordModifyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            editKeyword();
        }
    });
    keywordViewer.getControl().addKeyListener(keyListener);
    keywordViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(final SelectionChangedEvent event) {
            updateButtons();
            if (cntrlDwn) {
                if (keywordModifyButton.isEnabled())
                    editKeyword();
                cntrlDwn = false;
            }
        }
    });
    keywordReplaceButton = createPushButton(buttonGroup, Messages.EditMetaDialog_replace,
            Messages.EditMetaDialog_replace_tooltip);
    keywordReplaceButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String kw = (String) ((IStructuredSelection) keywordViewer.getSelection()).getFirstElement();
            if (kw != null) {
                KeywordDialog dialog = new KeywordDialog(getShell(),
                        NLS.bind(Messages.EditMetaDialog_replace_keyword, kw), null, keywords, null);
                if (dialog.open() == Window.OK) {
                    BagChange<String> result = dialog.getResult();
                    boolean found = false;
                    Set<String> added = result.getAdded();
                    if (added != null)
                        for (String s : added)
                            if (kw.equals(s)) {
                                found = true;
                                break;
                            }
                    if (!found)
                        removeKeywordFromViewer(keywordViewer, kw);
                    Set<String> addedKeywords = result.getAdded();
                    String[] replacement = addedKeywords.toArray(new String[addedKeywords.size()]);
                    int i = 0;
                    for (String k : replacement)
                        addKeywordToViewer(keywordViewer, k, i++ == 0);
                    todo.add(new ReplaceKeywordOperation(kw, replacement));
                }
            }
        }
    });
    keywordDeleteButton = createPushButton(buttonGroup, Messages.EditMetaDialog_delete_keyword,
            Messages.EditMetaDialog_delete_keyword_tooltip);
    keywordDeleteButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(keywordDeleteButton.getDisplay(), () -> {
                IStructuredSelection selection = (IStructuredSelection) keywordViewer.getSelection();
                String kw = (String) selection.getFirstElement();
                if (kw != null) {
                    List<AssetImpl> set = dbManager.obtainObjects(AssetImpl.class,
                            QueryField.IPTC_KEYWORDS.getKey(), kw, QueryField.EQUALS);
                    removeKeywordFromViewer(keywordViewer, kw);
                    if (!set.isEmpty()) {
                        KeywordDeleteDialog dialog = new KeywordDeleteDialog(getShell(), kw, set);
                        if (dialog.open() != Window.OK) {
                            keywords.add(kw);
                            return;
                        }
                        if (dialog.getPolicy() == KeywordDeleteDialog.REMOVE)
                            todo.add(new ManageKeywordsOperation(
                                    new BagChange<String>(null, null, Collections.singleton(kw), null), set));
                    }
                }
            });
        }
    });
    keywordShowButton = createPushButton(buttonGroup, Messages.EditMetaDialog_show_images,
            Messages.EditMetaDialog_show_keyword_tooltip);
    keywordShowButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) keywordViewer.getSelection();
            String kw = (String) selection.getFirstElement();
            if (kw != null) {
                SmartCollectionImpl sm = new SmartCollectionImpl(kw, false, false, true, false, null, 0, null,
                        0, null, Constants.INHERIT_LABEL, null, 0, null);
                sm.addCriterion(new CriterionImpl(QueryField.IPTC_KEYWORDS.getKey(), null, kw,
                        QueryField.EQUALS, false));
                sm.addSortCriterion(new SortCriterionImpl(QueryField.IPTC_DATECREATED.getKey(), null, true));
                Ui.getUi().getNavigationHistory(workbenchPage.getWorkbenchWindow())
                        .postSelection(new StructuredSelection(sm));
                close();
            }
        }
    });
    new Label(buttonGroup, SWT.SEPARATOR | SWT.HORIZONTAL);

    keywordCollectButton = createPushButton(buttonGroup, Messages.EditMetaDialog_collect,
            Messages.EditMetaDialog_collect_keyword_tooltip);
    keywordCollectButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            KeywordCollectDialog dialog = new KeywordCollectDialog(getShell(), keywords);
            if (dialog.open() == Window.OK) {
                int i = 0;
                for (String kw : dialog.getToAdd())
                    addKeywordToViewer(keywordViewer, kw, i++ == 0);
                for (String kw : dialog.getToRemove())
                    removeKeywordFromViewer(keywordViewer, kw);
            }
        }
    });

    keywordLoadButton = createPushButton(buttonGroup, Messages.EditMetaDialog_load,
            NLS.bind(Messages.EditMetaDialog_load_keyword_tooltip, Constants.KEYWORDFILEEXTENSION));
    keywordLoadButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent ev) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setFilterExtensions(KEYWORDEXTENSIONS);
            dialog.setFilterNames(
                    new String[] {
                            Constants.APPNAME + Messages.EditMetaDialog_zoom_keyword_file
                                    + Constants.KEYWORDFILEEXTENSION + ')',
                            Messages.EditMetaDialog_all_files });
            String filename = dialog.open();
            if (filename != null) {
                try (InputStream in = new BufferedInputStream(new FileInputStream(filename))) {
                    List<String> list = Utilities.loadKeywords(in);
                    keywords.clear();
                    keywords.addAll(list);
                } catch (IOException e) {
                    // ignore
                }
                keywordViewer.setInput(keywords);
                keywordViewer.expandAll();
            }
        }
    });
    keywordSaveButton = createPushButton(buttonGroup, Messages.EditMetaDialog_save,
            NLS.bind(Messages.EditMetaDialog_save_keyword_tooltip, Constants.KEYWORDFILEEXTENSION));
    keywordSaveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
            dialog.setFilterExtensions(KEYWORDEXTENSIONS);
            dialog.setFilterNames(
                    new String[] {
                            Constants.APPNAME + Messages.EditMetaDialog_zoom_keyword_file
                                    + Constants.KEYWORDFILEEXTENSION + ")", //$NON-NLS-1$
                            Messages.EditMetaDialog_all_files });
            dialog.setFileName("*" + Constants.KEYWORDFILEEXTENSION); //$NON-NLS-1$
            dialog.setOverwrite(true);
            String filename = dialog.open();
            if (filename != null)
                Utilities.saveKeywords(keywords, new File(filename));
        }
    });
    addToKeywordsButton = WidgetFactory.createCheckButton(kwGroup, Messages.EditMetaDialog_add_to_keywords,
            new GridData(SWT.BEGINNING, SWT.END, true, false, 2, 1));
    CGroup vocabGroup = new CGroup(kwComp, SWT.NONE);
    vocabGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    vocabGroup.setLayout(new GridLayout(2, false));
    vocabGroup.setText(Messages.EditMetaDialog_controlled_vocabs);
    Composite vocabViewerGroup = new Composite(vocabGroup, SWT.NONE);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.verticalIndent = 20;
    vocabViewerGroup.setLayoutData(layoutData);
    vocabViewerGroup.setLayout(new GridLayout(2, false));

    vocabViewer = new TableViewer(vocabViewerGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    setViewerLayout(vocabViewer, 150, 1);
    TableViewerColumn col1 = new TableViewerColumn(vocabViewer, SWT.NONE);
    col1.getColumn().setWidth(300);
    col1.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            return element.toString();
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof String && !new File((String) element).exists())
                return Icons.error.getImage();
            return null;
        }

        @Override
        public String getToolTipText(Object element) {
            if (element instanceof String && UiActivator.getDefault().getShowHover()) {
                File file = new File((String) element);
                if (!file.exists())
                    return Messages.EditMetaDialog_file_does_not_exist;
            }
            return super.getToolTipText(element);
        }

        @Override
        public Image getToolTipImage(Object element) {
            return getImage(element);
        }
    });
    vocabViewer.setContentProvider(ArrayContentProvider.getInstance());
    vocabViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
        }
    });
    vocabViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            viewVocab();
        }
    });
    ColumnViewerToolTipSupport.enableFor(vocabViewer);
    Composite vocabButtonGroup = new Composite(vocabViewerGroup, SWT.NONE);
    vocabButtonGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    vocabButtonGroup.setLayout(new GridLayout());
    vocabAddButton = createPushButton(vocabButtonGroup, Messages.EditMetaDialog_add,
            Messages.EditMetaDialog_add_vocab);
    vocabAddButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setText(Messages.EditMetaDialog_select_vocab);
            dialog.setFilterExtensions(KEYWORDEXTENSIONS);
            dialog.setFilterNames(
                    new String[] {
                            Constants.APPNAME + Messages.EditMetaDialog_zoom_keyword_file
                                    + Constants.KEYWORDFILEEXTENSION + ')',
                            Messages.EditMetaDialog_all_files });
            String file = dialog.open();
            if (file != null) {
                boolean found = false;
                for (String s : vocabularies)
                    if (s.equals(file)) {
                        found = true;
                        break;
                    }
                if (!found) {
                    vocabularies.add(file);
                    vocabViewer.add(file);
                }
                vocabViewer.setSelection(new StructuredSelection(file), true);
                if (vocabManager != null)
                    vocabManager.reset(vocabularies);
                updateKeywordViewer();
            }
        }
    });
    vocabRemoveButton = createPushButton(vocabButtonGroup, Messages.EditMetaDialog_remove,
            Messages.EditMetaDialog_remove_vocab);
    vocabRemoveButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            @SuppressWarnings("unchecked")
            Iterator<Object> it = vocabViewer.getStructuredSelection().iterator();
            while (it.hasNext()) {
                Object file = it.next();
                vocabularies.remove(file);
                vocabViewer.remove(file);
            }
            if (vocabManager != null)
                vocabManager.reset(vocabularies);
            updateKeywordViewer();
        }
    });
    vocabViewButton = createPushButton(vocabButtonGroup, Messages.EditMetaDialog_view_vocab,
            Messages.EditMetaDialog_view_vocab_tooltip);
    vocabViewButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            viewVocab();
        }
    });
    new Label(vocabButtonGroup, SWT.SEPARATOR | SWT.HORIZONTAL);
    vocabEnforceButton = createPushButton(vocabButtonGroup, Messages.EditMetaDialog_enforce,
            Messages.EditMetaDialog_enforce_tooltip);
    vocabEnforceButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            List<String[]> changes = new ArrayList<>();
            VocabManager vManager = getVocabManager();
            for (String kw : keywords) {
                String mapped = vManager.getVocab(kw);
                if (!kw.equals(mapped))
                    changes.add(new String[] { kw, mapped });
            }
            VocabEnforceDialog dialog = new VocabEnforceDialog(getShell(), changes);
            if (dialog.open() == VocabEnforceDialog.OK) {
                BusyIndicator.showWhile(getShell().getDisplay(), () -> {
                    int policy = dialog.getPolicy();
                    for (String[] change : dialog.getChanges()) {
                        String kw = change[0];
                        keywords.remove(kw);
                        if (change[1] != null) {
                            keywords.add(change[1]);
                            if (policy == KeywordDeleteDialog.REMOVE)
                                todo.add(new ReplaceKeywordOperation(kw, new String[] { change[1] }));
                        } else if (policy == KeywordDeleteDialog.REMOVE)
                            todo.add(new ManageKeywordsOperation(
                                    new BagChange<String>(null, null, Collections.singleton(kw), change),
                                    null));
                        updateKeywordViewer();
                    }

                });
            }
        }
    });
}