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:cn.edu.pku.ogeditor.views.ConceptOutlineView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    // TODO Auto-generated method stub
    tv = new TreeViewer(parent, SWT.BORDER);
    tv.setContentProvider(new ConceptOutlineContentProvider());
    tv.setLabelProvider(new ConceptOutlineLabelProvider());
    ShapesEditor editor = null;//ww w.  j av a  2 s. com
    if ((editor = getShapesEditor()) != null) {
        tv.setInput(editor.getDiagram());
    }
    getSite().getPage().addSelectionListener(this);

}

From source file:cn.edu.pku.ogeditor.views.HierarchyView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    // TODO Auto-generated method stub

    viewer = new TreeViewer(parent, SWT.SINGLE);
    final Tree tree = viewer.getTree();
    ce = new TreeEditor(tree);
    tree.setHeaderVisible(true);//  w w  w.jav a  2s . c om
    tree.setLinesVisible(true);
    viewer.setContentProvider(new HierarchyContentProvider());
    viewer.setLabelProvider(new HierarchyLabelProvider());
    ShapesEditor editor = null;
    if ((editor = getShapesEditor()) != null) {
        // List<ShapesDiagram> diagrams = new ArrayList<ShapesDiagram>();
        // diagrams.add(editor.getDiagram().getRootDiagram());
        viewer.setInput(editor);
    }
    viewer.addSelectionChangedListener(new LevelChangeListener());
    viewer.addDoubleClickListener(new RenameListener());
    // getSite().setSelectionProvider(viewer);
    getSite().getPage().addSelectionListener(this);
    Menu menu = new Menu(parent);
    tree.setMenu(menu);
    MenuItem menuItem1 = new MenuItem(menu, SWT.NONE);
    menuItem1.setText("Add Lower Level Ontology");
    menuItem1.addSelectionListener(new AddChildListener());
    MenuItem menuItem2 = new MenuItem(menu, SWT.NONE);
    menuItem2.setText("Remove Ontology");
    menuItem2.addSelectionListener(new RemoveOntologyListener());
    MenuItem menuItem3 = new MenuItem(menu, SWT.NONE);
    menuItem3.setText("Rename");
    menuItem3.addSelectionListener(new RenameListener());
}

From source file:cn.ieclipse.adt.ext.wizards.EditComponentWizardPage.java

License:Apache License

public void createControl(Composite parent) {

    GC gc = new GC(parent);
    gc.setFont(parent.getFont());/*from  ww  w. j a  va 2 s  .com*/
    fontMetrics = gc.getFontMetrics();
    gc.dispose();
    // for (ComponentAttribute attr : attributes) {
    // createAttrFiled(container, layout.numColumns, attr);
    // }
    SashForm sashForm = new SashForm(parent, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite composite_1 = new Composite(sashForm, SWT.NONE);
    composite_1.setLayout(new GridLayout(1, false));

    ToolBar toolBar = new ToolBar(composite_1, SWT.FLAT | SWT.RIGHT);
    toolBar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));

    final ToolItem tbAdd = new ToolItem(toolBar, SWT.NONE);
    tbAdd.setToolTipText("Add");
    tbAdd.setImage(ADD_IMG);

    final ToolItem tbDelete = new ToolItem(toolBar, SWT.NONE);
    tbDelete.setImage(DEL_IMG);
    tbDelete.setToolTipText("Delete");

    final ToolItem tbUp = new ToolItem(toolBar, SWT.NONE);
    tbUp.setToolTipText("Up");
    tbUp.setImage(UP_IMG);

    final ToolItem tbDown = new ToolItem(toolBar, SWT.NONE);
    tbDown.setToolTipText("Down");
    tbDown.setImage(DOWN_IMG);

    tbAdd.addSelectionListener(new MenuItemSelectionAdapter(MID_ADD));
    tbDelete.addSelectionListener(new MenuItemSelectionAdapter(MID_DELETE));
    tbUp.addSelectionListener(new MenuItemSelectionAdapter(MID_UP));
    tbDown.addSelectionListener(new MenuItemSelectionAdapter(MID_DOWN));
    tbAdd.setEnabled(false);
    tbDelete.setEnabled(false);
    tbUp.setEnabled(false);
    tbDown.setEnabled(false);

    final ToolItem tbTip = new ToolItem(toolBar, SWT.CHECK);
    tbTip.setImage(SWTResourceManager.getImage(org.eclipse.jdt.ui.ISharedImages.class,
            "/icons/full/obj16/translate.png"));
    tbTip.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            TipShell.setShow(tbTip.getSelection());
            if (tbTip.getSelection()) {
                tbTip.setImage(SWTResourceManager.getImage(org.eclipse.jdt.ui.ISharedImages.class,
                        "/icons/full/obj16/never_translate.png"));
            } else {
                tbTip.setImage(SWTResourceManager.getImage(org.eclipse.jdt.ui.ISharedImages.class,
                        "/icons/full/obj16/translate.png"));
            }
        }
    });

    tbTip.setToolTipText("Show/Hide tooltip text for attribute");
    // tbTip.setText("Show attribute tooltip");

    treeViewer = new TreeViewer(composite_1, SWT.BORDER);
    Tree tree = treeViewer.getTree();
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Menu menu = new Menu(tree);
    tree.setMenu(menu);

    final MenuItem miAdd = new MenuItem(menu, SWT.NONE);
    miAdd.setText("Add");
    miAdd.setID(MID_ADD);
    miAdd.setImage(ADD_IMG);

    // final MenuItem miCopy = new MenuItem(menu, SWT.NONE);
    // miCopy.setText("Copy");
    // miCopy.setID(MID_COPY);
    //
    // final MenuItem miPaste = new MenuItem(menu, SWT.NONE);
    // miPaste.setText("Paste");
    // miPaste.setID(MID_PASTE);

    final MenuItem miDel = new MenuItem(menu, SWT.NONE);
    miDel.setText("Delete");
    miDel.setID(MID_DELETE);
    miDel.setImage(DEL_IMG);

    final MenuItem miUp = new MenuItem(menu, SWT.NONE);
    miUp.setText("Up");
    miUp.setID(MID_UP);
    miUp.setImage(UP_IMG);

    final MenuItem miDown = new MenuItem(menu, SWT.NONE);
    miDown.setText("Down");
    miDown.setID(MID_DOWN);
    miDown.setImage(DOWN_IMG);

    miAdd.addSelectionListener(new MenuItemSelectionAdapter(MID_ADD));
    miDel.addSelectionListener(new MenuItemSelectionAdapter(MID_DELETE));
    miUp.addSelectionListener(new MenuItemSelectionAdapter(MID_UP));
    miDown.addSelectionListener(new MenuItemSelectionAdapter(MID_DOWN));

    menu.addMenuListener(new MenuAdapter() {
        @Override
        public void menuShown(MenuEvent e) {
            miUp.setEnabled(selectedNode != rootNode);
            miDown.setEnabled(selectedNode != rootNode);

            boolean canAdd = selectedNode != null;
            if (canAdd) {
                ComponentElement ce = getNodeAttrCache().get(selectedNode);
                canAdd = canAdd && !ce.getChildren().isEmpty();
                miAdd.setEnabled(canAdd);
            }
        }
    });

    treeViewer.setLabelProvider(new NodeLabelProvider());
    treeViewer.setContentProvider(new NodeContentProvider());
    treeViewer.setAutoExpandLevel(5);

    treeViewer.setInput(rootNode);
    treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            update(sel.getFirstElement());

            tbUp.setEnabled(selectedNode != rootNode);
            tbDown.setEnabled(selectedNode != rootNode);
            tbDelete.setEnabled(selectedNode != null);

            boolean canAdd = selectedNode != null;
            if (canAdd) {
                ComponentElement ce = getNodeAttrCache().get(selectedNode);
                canAdd = canAdd && !ce.getChildren().isEmpty();
                tbAdd.setEnabled(canAdd);
            }
            fireTreeUpdated();
        }
    });
    treeViewer.getTree().forceFocus();
    treeViewer.setAutoExpandLevel(3);

    scrolledComposite = new ScrolledComposite(sashForm, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);

    scrolledComposite.setLayout(new FillLayout());
    composite = new Composite(scrolledComposite, SWT.NONE);
    scrolledComposite.setContent(composite);
    layout = new GridLayout();
    layout.numColumns = 4;
    layout.makeColumnsEqualWidth = false;
    composite.setLayout(layout);
    scrolledComposite.setMinSize(480, 320);
    sashForm.setWeights(new int[] { 400, 480 });
    setControl(sashForm);
}

From source file:coloredide.astview.ASTView.java

License:Open Source License

public void createPartControl(Composite parent) {
    fSash = new SashForm(parent, SWT.VERTICAL | SWT.SMOOTH);
    fViewer = new TreeViewer(fSash, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    fDrillDownAdapter = new DrillDownAdapter(fViewer);
    fViewer.setContentProvider(new ASTViewContentProvider());
    fASTLabelProvider = new ASTViewLabelProvider(this);
    fViewer.setLabelProvider(fASTLabelProvider);
    fViewer.addSelectionChangedListener(fSuperListener);
    fViewer.addDoubleClickListener(fSuperListener);
    fViewer.addFilter(fNonRelevantFilter);

    ViewForm trayForm = new ViewForm(fSash, SWT.NONE);
    Label label = new Label(trayForm, SWT.NONE);
    label.setText(" Comparison Tray (* = selection in the upper tree):"); //$NON-NLS-1$
    trayForm.setTopLeft(label);/*from  w w w .  j  av  a2 s .  c  o  m*/

    fTray = new TreeViewer(trayForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    trayForm.setContent(fTray.getTree());

    fTrayRoots = new ArrayList();
    fTray.setContentProvider(new TrayContentProvider());
    final TrayLabelProvider trayLabelProvider = new TrayLabelProvider();
    fTray.setLabelProvider(trayLabelProvider);
    fTray.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    fTrayUpdater = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection viewerSelection = (IStructuredSelection) fViewer.getSelection();
            if (viewerSelection.size() == 1) {
                if (DynamicAttributeProperty.unwrapAttribute(viewerSelection.getFirstElement()) != null) {
                    trayLabelProvider.setViewerElement(viewerSelection.getFirstElement());
                    return;
                }
            }
            trayLabelProvider.setViewerElement(null);
        }
    };
    fTray.addPostSelectionChangedListener(fTrayUpdater);
    fViewer.addPostSelectionChangedListener(fTrayUpdater);
    fTray.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            performTrayDoubleClick();
        }
    });
    fTray.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            boolean deleteEnabled = false;
            if (selection.size() == 1 && selection.getFirstElement() instanceof Binding)
                deleteEnabled = fTray.getTree().isFocusControl();
            fDeleteAction.setEnabled(deleteEnabled);
        }
    });
    fTray.getTree().addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fTray.getSelection();
            boolean deleteEnabled = false;
            if (selection.size() == 1 && selection.getFirstElement() instanceof Binding)
                deleteEnabled = true;
            fDeleteAction.setEnabled(deleteEnabled);
        }

        public void focusLost(FocusEvent e) {
            fDeleteAction.setEnabled(false);
        }
    });

    makeActions();
    hookContextMenu();
    hookTrayContextMenu();
    contributeToActionBars();
    getSite().setSelectionProvider(new ASTViewSelectionProvider());

    try {
        IEditorPart part = EditorUtility.getActiveEditor();
        if (part instanceof ITextEditor) {
            setInput((ITextEditor) part);
        }
    } catch (CoreException e) {
        // ignore
    }
    if (fColoredJavaSourceFile == null) {
        clearView();
    } else {
        setASTUptoDate(fColoredJavaSourceFile != null);
    }
}

From source file:com.alibaba.antx.config.gui.MainWindow.java

License:Open Source License

/**
 * Create contents of the application window
 * /*from   w w w  .  j a  va2  s.  com*/
 * @param parent
 */
protected Control createContents(Composite parent) {
    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    Composite leftPane = new Composite(sashForm, SWT.BORDER);
    Composite rightPane = new Composite(sashForm, SWT.BORDER);

    leftPane.setLayout(new GridLayout());
    rightPane.setLayout(new GridLayout());

    TreeViewer entriesViewer = new TreeViewer(leftPane, SWT.BORDER);

    entriesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    entriesViewer.setContentProvider(new ITreeContentProvider() {
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof List) {
                List entriesList = (List) parentElement;
                return (ConfigEntry[]) entriesList.toArray(new ConfigEntry[entriesList.size()]);
            }

            return null;
        }

        public Object getParent(Object element) {
            return null;
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List) {
                List entriesList = (List) inputElement;
                return (ConfigEntry[]) entriesList.toArray(new ConfigEntry[entriesList.size()]);
            }

            return null;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });

    gui.scan();
    entriesViewer.setInput(gui.getEntries());

    return sashForm;
}

From source file:com.amalto.workbench.detailtabs.sections.composites.EntityKeyConfigComposite.java

License:Open Source License

public EntityKeyConfigComposite(Composite parent, int style) {
    super(parent, style);
    setLayout(new FillLayout());

    final SashForm sashForm = new SashForm(this, SWT.NONE);
    sashForm.setSashWidth(2);//from w w w . ja v  a  2s .  c om
    sashForm.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    final Composite compKeys = new Composite(sashForm, SWT.NONE);
    compKeys.setLayout(new GridLayout());
    compKeys.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    tvKeys = new TreeViewer(compKeys, SWT.BORDER | SWT.FULL_SELECTION);
    Tree trKeys = tvKeys.getTree();
    trKeys.setLinesVisible(true);
    final GridData gd_trKeys = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_trKeys.widthHint = 165;
    trKeys.setLayoutData(gd_trKeys);

    final Composite compKeyBtns = new Composite(compKeys, SWT.NONE);
    compKeyBtns.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    final GridData gd_compKeyBtns = new GridData(SWT.FILL, SWT.CENTER, true, false);
    compKeyBtns.setLayoutData(gd_compKeyBtns);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    compKeyBtns.setLayout(gridLayout);

    btnAddKey = new Button(compKeyBtns, SWT.NONE);
    btnAddKey.setToolTipText(Messages.EntityKeyConfigComposite_0);
    btnAddKey.setImage(addKeyIcon);

    btnDeleteKey = new Button(compKeyBtns, SWT.NONE);
    btnDeleteKey.setToolTipText(Messages.EntityKeyConfigComposite_1);
    btnDeleteKey.setImage(deleteKeyIcon);

    final Composite compKeyInfo = new Composite(sashForm, SWT.NONE);
    compKeyInfo.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    final GridLayout gridLayout_2 = new GridLayout();
    compKeyInfo.setLayout(gridLayout_2);

    final Composite composite = new Composite(compKeyInfo, SWT.NONE);
    composite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    final GridLayout gridLayout_3 = new GridLayout();
    gridLayout_3.marginWidth = 0;
    gridLayout_3.marginHeight = 0;
    gridLayout_3.numColumns = 2;
    composite.setLayout(gridLayout_3);

    final Label lblKeyName = new Label(composite, SWT.NONE);
    lblKeyName.setText(Messages.EntityKeyConfigComposite_2);
    lblKeyName.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    lblKeyNameErrIndicator = new Label(composite, SWT.NONE);
    lblKeyNameErrIndicator.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    lblKeyNameErrIndicator.setImage(errIcon);
    lblKeyNameErrIndicator.setVisible(false);

    txtKeyName = new Text(compKeyInfo, SWT.BORDER);
    final GridData gd_txtKeyName = new GridData(SWT.FILL, SWT.CENTER, true, false);
    txtKeyName.setLayoutData(gd_txtKeyName);

    final Label lblSelector = new Label(compKeyInfo, SWT.NONE);
    lblSelector.setText(Messages.EntityKeyConfigComposite_Selector);
    lblSelector.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    comboSelector = new Combo(compKeyInfo, SWT.BORDER);
    final GridData gd_comboSelector = new GridData(SWT.FILL, SWT.CENTER, true, false);
    comboSelector.setLayoutData(gd_comboSelector);

    final Label lblFields = new Label(compKeyInfo, SWT.NONE);
    lblFields.setText(Messages.EntityKeyConfigComposite_Fields);
    lblFields.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));

    tvFields = new TreeViewer(compKeyInfo, SWT.BORDER | SWT.FULL_SELECTION);
    Tree trFields = tvFields.getTree();
    trFields.setLinesVisible(true);
    final GridData gd_trFields = new GridData(SWT.FILL, SWT.FILL, true, true);
    trFields.setLayoutData(gd_trFields);

    final Composite compFieldBtns = new Composite(compKeyInfo, SWT.NONE);
    compFieldBtns.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    final GridData gd_compFieldBtns = new GridData(SWT.FILL, SWT.CENTER, true, false);
    compFieldBtns.setLayoutData(gd_compFieldBtns);
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.numColumns = 3;
    compFieldBtns.setLayout(gridLayout_1);

    btnAddField = new Button(compFieldBtns, SWT.NONE);
    btnAddField.setToolTipText(Messages.EntityKeyConfigComposite_AddField);
    btnAddField.setImage(addFieldIcon);

    btnEditField = new Button(compFieldBtns, SWT.NONE);
    btnEditField.setToolTipText(Messages.EntityKeyConfigComposite_EditFields);
    btnEditField.setImage(editFieldIcon);

    btnDeleteField = new Button(compFieldBtns, SWT.NONE);
    btnDeleteField.setToolTipText(Messages.EntityKeyConfigComposite_DelField);
    btnDeleteField.setImage(deleteFieldIcon);

    tvKeys.setContentProvider(new ListContentProvider());
    tvKeys.setLabelProvider(new KeyWrapperLabelProvider());

    tvFields.setContentProvider(new ListContentProvider());
    tvFields.setLabelProvider(new FieldWrapperLabelProvider());

    sashForm.setWeights(new int[] { 190, 308 });

    initUIListeners();

    addUIListeners();
}

From source file:com.amalto.workbench.detailtabs.sections.composites.LanguageInfoComposite.java

License:Open Source License

public LanguageInfoComposite(Composite parent, int style, BasePropertySection section) {
    super(parent, style);
    this.section = section;
    allLanguages = Arrays.asList(Util.lang2iso.keySet().toArray(new String[0]));

    final GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 4;// w  ww.  j  a  v  a 2 s.c o  m
    setLayout(gridLayout);

    comboLanguage = new Combo(this, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    final GridData gd_comboLanguage = new GridData();
    gd_comboLanguage.widthHint = 120;
    comboLanguage.setLayoutData(gd_comboLanguage);

    txtLabel = new Text(this, SWT.BORDER);
    final GridData gd_txtLabel = new GridData(SWT.FILL, SWT.CENTER, true, false);
    txtLabel.setLayoutData(gd_txtLabel);

    btnAdd = new Button(this, SWT.NONE);
    btnAdd.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    btnAdd.setToolTipText(Messages.Add);

    tvInfos = new TreeViewer(this, SWT.BORDER | SWT.FULL_SELECTION);
    Tree tree = tvInfos.getTree();
    tree.setHeaderVisible(true);
    tree.setLinesVisible(true);
    final GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd_tree.heightHint = 80;
    tree.setLayoutData(gd_tree);

    final TreeColumn colLanguage = new TreeColumn(tree, SWT.NONE);
    colLanguage.setWidth(120);
    colLanguage.setText(Messages.LanguageInfoComposite_);

    final TreeColumn colLabel = new TreeColumn(tree, SWT.NONE);
    colLabel.setWidth(242);
    colLabel.setText(Messages.LanguageInfoComposite_Label);

    btnRemove = new Button(this, SWT.NONE);
    final GridData gd_btnRemove = new GridData(SWT.LEFT, SWT.TOP, false, false);
    btnRemove.setLayoutData(gd_btnRemove);
    btnRemove.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    btnRemove.setToolTipText(Messages.LanguageInfoComposite_Del);
    //

    tvInfos.setContentProvider(new ListContentProvider());
    tvInfos.setLabelProvider(new LanguageInfoLabelProvider());
    tvInfos.setSorter(new LanguageInfoSorter());

    initUIListeners();
}

From source file:com.amalto.workbench.dialogs.DataModelSelectDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(Messages.DataModelSelectDialog_SelectDataModel);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.makeColumnsEqualWidth = false;
    schemaLabel = new Label(composite, SWT.NONE);
    schemaLabel.setText(title);//from  w w w .  j  a  v  a 2 s. c o m
    GridData dg = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
    domViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.MULTI);
    domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    ((GridData) domViewer.getControl().getLayoutData()).heightHint = 400;
    ((GridData) domViewer.getControl().getLayoutData()).widthHint = 400;
    changeToResource();
    selectDataModel();
    return composite;
}

From source file:com.amalto.workbench.dialogs.DOMViewDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    try {/*  w w w  . j av  a  2s  . c om*/
        // Should not really be here but well,....
        if (editable) {
            parent.getShell().setText(Messages.DOMViewDialog_EditorViewer);
        } else {
            parent.getShell().setText(Messages.DOMViewDialog_Viewer);
        }

        Composite composite = new Composite(parent, SWT.NULL);
        GridLayout layout = new GridLayout();
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
        applyDialogFont(composite);

        if (desc != null && desc.length() > 0) {
            new Label(composite, SWT.NONE).setText(desc);
        }

        tabFolder = new TabFolder(composite, SWT.TOP | SWT.H_SCROLL | SWT.V_SCROLL);
        tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) tabFolder.getLayoutData()).heightHint = 600;
        ((GridData) tabFolder.getLayoutData()).widthHint = 600;

        tabFolder.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                if (tabFolder.getSelectionIndex() == 0) {
                    if (node == null) {
                        try {

                            if (sourceViewer == null || sourceViewer.getDocument() == null) {
                                return;
                            }
                            node = Util.parse(sourceViewer.getText());

                        } catch (Exception ex) {

                            log.error(ex.getMessage(), ex);
                            tabFolder.setSelection(1);
                            MessageDialog.openError(DOMViewDialog.this.getShell(),
                                    Messages.DOMViewDialog_XMLInvalid, Messages.bind(
                                            Messages.DOMViewDialog_XMLInvalidInfo, ex.getLocalizedMessage()));
                            return;
                        }
                        domViewer.setInput(node);
                        domViewer.expandAll();
                    }
                } else if (tabFolder.getSelectionIndex() == 1) {
                    try {
                        sourceViewer.setText(Util.nodeToString(node));
                        node = null; // this should be better implemented in a change listener on the text
                    } catch (Exception ex) {
                        MessageDialog.openError(DOMViewDialog.this.getShell(),
                                Messages.DOMViewDialog_ErrorTitle,
                                Messages.bind(Messages.DOMViewDialog_ErrorMsg, ex.getLocalizedMessage()));
                        sourceViewer.setText(""); //$NON-NLS-1$
                    }
                }
            }// widget Selected
        });

        TabItem tiDOM = new TabItem(tabFolder, SWT.NULL);
        tiDOM.setText(Messages.DOMViewDialog_Tree);
        tiDOM.setToolTipText(Messages.DOMViewDialog_DisplayAsDomTree);

        domViewer = new TreeViewer(tabFolder, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
        domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        // ((GridData)domViewer.getControl().getLayoutData()).heightHint=300;
        // ((GridData)domViewer.getControl().getLayoutData()).widthHint=300;
        domViewer.setSorter(null);
        domViewer.setLabelProvider(new DOMTreeLabelProvider());
        domViewer.setContentProvider(new DOMTreeContentProvider());
        domViewer.setInput(node);
        domViewer.expandAll();
        domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        tiDOM.setControl(domViewer.getControl());

        TabItem tiSource = new TabItem(tabFolder, SWT.NULL);
        tiSource.setText(Messages.DOMViewDialog_TiSourceText);
        tiSource.setToolTipText(Messages.DOMViewDialog_TiSourceTip);

        XMLSourceViewerHelper sourceViewerHelper = XMLSourceViewerHelper.getInstance();
        sourceViewer = new XMLSourceViewer(tabFolder, sourceViewerHelper.createVerticalRuler(),
                sourceViewerHelper.createOverviewRuler(), true, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        XMLConfiguration sourceViewerConfiguration = new XMLConfiguration(this);
        sourceViewer.configure(sourceViewerConfiguration);
        sourceViewer.initilize();
        sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        sourceViewer.setText(Util.nodeToString(node));
        sourceViewer.setEditable(this.editable);
        /*
         * sourceViewer.addTextListener( new ITextListener() { public void
         * textChanged(org.eclipse.jface.text.TextEvent event) { if ((event.getText()==null) ||
         * ("".equals(event.getText()))) return; node = null; elementChanged = true; } } );
         */
        tiSource.setControl(sourceViewer.getControl());

        tabFolder.setSelection(firstTab);
        if (firstTab == SOURCE_VIEWER) {
            node = null; // force refresh of tree
        }

        return composite;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.getShell(), Messages._Error,
                Messages.bind(Messages.DOMViewDialog_ErrorMsg1, e.getLocalizedMessage()));
        return null;
    }

}

From source file:com.amalto.workbench.dialogs.XpathSelectDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.makeColumnsEqualWidth = false;
    layout.numColumns = 2;/* www.  ja  va2  s . co  m*/
    Label datamoelsLabel = new Label(composite, SWT.NONE);
    GridData dg = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
    datamoelsLabel.setLayoutData(dg);
    datamoelsLabel.setText(Messages.XpathSelectDialog_DataModels);
    dg = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    dg.widthHint = 400;
    dataModelCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    dataModelCombo.setLayoutData(dg);
    // Modified by hbhong,to fix bug 21784|the following can cause potential error,so comment it
    // if (this.parent == null) {
    // this.parent = (TreeParent) ServerView.show().getRoot().getChildren()[0];
    // }
    // The ending| bug:21784

    final TreeParent tree = this.parent == null ? null : this.parent.findServerFolder(TreeObject.DATA_MODEL);

    // filter the datamodel according to conceptName
    if (tree != null) {
        avaiList = getAvailableDataModel();
    } else {
        avaiList = MDMRepositoryViewExtensionService.findAllDataModelNames();
    }

    dataModelCombo.setItems(avaiList.toArray(new String[avaiList.size()]));
    dataModelCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            changeDomTree(tree, filterText.getText());
        }
    });
    schemaLabel = new Label(composite, SWT.NONE);
    schemaLabel.setText(Messages.XpathSelectDialog_Xpath);
    schemaLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    ((GridData) schemaLabel.getLayoutData()).widthHint = 10;
    xpathText = new Text(composite, SWT.BORDER);
    xpathText.setEditable(false);
    xpathText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    // add the filter for the xpath,see bug 0016511: Entity filtering in select multiple xpath dialog:
    Label filterLabel = new Label(composite, SWT.NONE);
    filterLabel.setText(Messages.XpathSelectDialog_Filter);
    filterLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    filterText = new Text(composite, SWT.BORDER);
    filterText.setEditable(true);
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    if (conceptName != null) {
        filterText.setText(conceptName);
    } else {
        filterText.setText("");//$NON-NLS-1$
    }
    filterText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String filter = ((Text) e.widget).getText();
            changeDomTree(tree, filter);
        }
    });
    if (isMulti) {
        domViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    } else {
        domViewer = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    }
    int index = avaiList.indexOf(dataModelName);
    if (index < 0) {
        dataModelCombo.select(0);
    } else {
        dataModelCombo.select(index);
    }
    dataModelCombo.setEnabled(!lock);
    changeDomTree(tree, filterText.getText());

    domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) domViewer.getControl().getLayoutData()).heightHint = 400;
    ((GridData) domViewer.getControl().getLayoutData()).widthHint = 400;
    return composite;
}