Search in sources :

Example 6 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project netxms by netxms.

the class ObjectBrowser method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    FormLayout formLayout = new FormLayout();
    parent.setLayout(formLayout);
    // Read custom root objects
    long[] rootObjects = null;
    objectTree = new ObjectTree(parent, SWT.NONE, ObjectTree.MULTI, rootObjects, null, true, true);
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    objectTree.setLayoutData(fd);
    objectTree.setHideSubInterfaces(initHideSubInterfaces);
    objectTree.setHideTemplateChecks(initHideTemplateChecks);
    objectTree.setHideUnmanaged(initHideUnmanaged);
    objectTree.enableFilter(initShowFilter);
    objectTree.enableStatusIndicator(initShowStatus);
    objectTree.addOpenListener(new ObjectOpenListener() {

        @Override
        public boolean openObject(AbstractObject object) {
            return callOpenObjectHandler(object);
        }
    });
    createActions();
    createMenu();
    createToolBar();
    createPopupMenu();
    objectTree.enableDropSupport(this);
    objectTree.enableDragSupport();
    getSite().setSelectionProvider(objectTree.getTreeViewer());
    objectTree.getTreeViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) objectTree.getTreeViewer().getSelection()).size();
            actionMoveObject.setEnabled(size == 1);
        }
    });
    objectTree.setFilterCloseAction(new Action() {

        @Override
        public void run() {
            actionShowFilter.setChecked(false);
            objectTree.enableFilter(false);
        }
    });
    final TreeViewer tree = objectTree.getTreeViewer();
    TreeViewerEditor.create(tree, new ColumnViewerEditorActivationStrategy(tree) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    }, ColumnViewerEditor.DEFAULT);
    TextCellEditor editor = new TextCellEditor(tree.getTree(), SWT.BORDER);
    editor.addListener(new ICellEditorListener() {

        @Override
        public void editorValueChanged(boolean oldValidState, boolean newValidState) {
        }

        @Override
        public void cancelEditor() {
            objectTree.enableRefresh();
        }

        @Override
        public void applyEditorValue() {
        }
    });
    // TODO: override editor method that creates control to disable refresh
    tree.setCellEditors(new CellEditor[] { editor });
    // $NON-NLS-1$
    tree.setColumnProperties(new String[] { "name" });
    tree.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            final Object data = (element instanceof Item) ? ((Item) element).getData() : element;
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (data instanceof AbstractObject) {
                    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
                    final String newName = value.toString();
                    new ConsoleJob(Messages.get().ObjectBrowser_RenameJobName, null, Activator.PLUGIN_ID, null) {

                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception {
                            session.setObjectName(((AbstractObject) data).getObjectId(), newName);
                        }

                        @Override
                        protected String getErrorMessage() {
                            return String.format(Messages.get().ObjectBrowser_RenameJobError, ((AbstractObject) data).getObjectName());
                        }
                    }.start();
                }
            }
            objectTree.enableRefresh();
        }

        @Override
        public Object getValue(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AbstractObject) {
                    return ((AbstractObject) element).getObjectName();
                }
            }
            return null;
        }

        @Override
        public boolean canModify(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                objectTree.disableRefresh();
                return true;
            }
            // $NON-NLS-1$
            return false;
        }
    });
    activateContext();
    restoreSelection();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ObjectOpenListener(org.netxms.ui.eclipse.objectbrowser.api.ObjectOpenListener) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) NXCSession(org.netxms.client.NXCSession) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) Item(org.eclipse.swt.widgets.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) ICellEditorListener(org.eclipse.jface.viewers.ICellEditorListener) ObjectTree(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectTree) AbstractObject(org.netxms.client.objects.AbstractObject) ICellModifier(org.eclipse.jface.viewers.ICellModifier) AbstractObject(org.netxms.client.objects.AbstractObject) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 7 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project translationstudio8 by heartsome.

the class GridTableViewer method editElement.

/**
	 * {@inheritDoc}
	 */
public void editElement(Object element, int column) {
    try {
        getControl().setRedraw(false);
        Widget item = findItem(element);
        if (item != null) {
            ViewerRow row = getViewerRowFromItem(item);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                }
            }
        }
    } finally {
        getControl().setRedraw(true);
    }
// }
}
Also used : Widget(org.eclipse.swt.widgets.Widget) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 8 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project netxms by netxms.

the class AgentFileManager method enableInPlaceRename.

/**
 * Enable in-place renames
 */
private void enableInPlaceRename() {
    TreeViewerEditor.create(viewer, new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
        }
    }, ColumnViewerEditor.DEFAULT);
    viewer.setCellEditors(new CellEditor[] { new TextCellEditor(viewer.getTree()) });
    // $NON-NLS-1$
    viewer.setColumnProperties(new String[] { "name" });
    viewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            if (element instanceof Item)
                element = ((Item) element).getData();
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AgentFile) {
                    doRename((AgentFile) element, value.toString());
                }
            }
        }

        @Override
        public Object getValue(Object element, String property) {
            if (// $NON-NLS-1$
            property.equals("name")) {
                if (element instanceof AgentFile) {
                    return ((AgentFile) element).getName();
                }
            }
            return null;
        }

        @Override
        public boolean canModify(Object element, String property) {
            // $NON-NLS-1$
            return property.equals("name");
        }
    });
}
Also used : Item(org.eclipse.swt.widgets.Item) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) AgentFile(org.netxms.client.server.AgentFile) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 9 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project netxms by netxms.

the class GalleryTreeViewer method editElement.

public void editElement(Object element, int column) {
    if (element instanceof TreePath) {
        setSelection(new TreeSelection((TreePath) element));
        GalleryItem[] items = gallery.getSelection();
        if (items.length == 1) {
            ViewerRow row = getViewerRowFromItem(items[0]);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    getControl().setRedraw(false);
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                    getControl().setRedraw(true);
                }
            }
        }
    } else {
        super.editElement(element, column);
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 10 with ColumnViewerEditorActivationEvent

use of org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent in project usbdm-eclipse-plugins by podonoghue.

the class PeripheralConfigurationEditor method createPeripheralsTab.

// class SelectViewAction extends MyAction {
// private final Control fPanel;
// 
// SelectViewAction(String text, String toolTip, int style, String imageId, Control panel) {
// super(text, style);
// fPanel = panel;
// }
// 
// @Override
// public void run() {
// stackLayout.topControl = fPanel;
// panel.layout();
// }
// }
TabItem createPeripheralsTab(TabFolder parent) {
    TabItem tabItem = new TabItem(parent, SWT.NONE);
    tabItem.setText("Peripherals");
    Composite composite = new Composite(tabFolder, SWT.NONE);
    composite.setLayout(new FillLayout());
    tabItem.setControl(composite);
    TreeViewer viewer = new TreeViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    Tree tree = viewer.getTree();
    tree.setLinesVisible(true);
    tree.setHeaderVisible(true);
    ColumnViewerToolTipSupport.enableFor(viewer);
    // viewer.setContentProvider(new ViewContentProvider());
    ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {

        @Override
        protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
            return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION;
        }
    };
    TreeViewerEditor.create(viewer, actSupport, ColumnViewerEditor.DEFAULT);
    /*
       * Do columns
       */
    TreeViewerColumn column;
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.getColumn().setWidth(400);
    column.getColumn().setText("Option Name");
    column.getColumn().setResizable(true);
    column.setLabelProvider(new MyNameColumnLabelProvider());
    column = new TreeViewerColumn(viewer, SWT.NONE);
    column.getColumn().setWidth(300);
    column.getColumn().setText("Option Value");
    column.getColumn().setResizable(true);
    return tabItem;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) ColumnViewerEditorActivationStrategy(org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Tree(org.eclipse.swt.widgets.Tree) FillLayout(org.eclipse.swt.layout.FillLayout) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn)

Aggregations

ColumnViewerEditorActivationEvent (org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent)15 ColumnViewerEditorActivationStrategy (org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy)11 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 TableViewer (org.eclipse.jface.viewers.TableViewer)5 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)5 GridData (org.eclipse.swt.layout.GridData)5 Composite (org.eclipse.swt.widgets.Composite)5 ICellModifier (org.eclipse.jface.viewers.ICellModifier)4 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)4 FocusCellOwnerDrawHighlighter (org.eclipse.jface.viewers.FocusCellOwnerDrawHighlighter)3 TableViewerFocusCellManager (org.eclipse.jface.viewers.TableViewerFocusCellManager)3 ViewerCell (org.eclipse.jface.viewers.ViewerCell)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Tree (org.eclipse.swt.widgets.Tree)3 ArrayList (java.util.ArrayList)2 CellNavigationStrategy (org.eclipse.jface.viewers.CellNavigationStrategy)2 ICellEditorListener (org.eclipse.jface.viewers.ICellEditorListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)2