Search in sources :

Example 1 with GraphTreeLabelProvider

use of org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeLabelProvider in project netxms by netxms.

the class PredefinedGraphTree method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    parent.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(parent, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
        }
    });
    viewer = new TreeViewer(parent, SWT.NONE);
    viewer.setUseHashlookup(true);
    viewer.setContentProvider(new GraphTreeContentProvider());
    viewer.setLabelProvider(new GraphTreeLabelProvider());
    viewer.setComparer(new IElementComparer() {

        @Override
        public int hashCode(Object element) {
            if ((element instanceof GraphSettings)) {
                return (int) ((GraphSettings) element).getId();
            }
            if ((element instanceof GraphFolder)) {
                return ((GraphFolder) element).getName().hashCode();
            }
            return element.hashCode();
        }

        @Override
        public boolean equals(Object a, Object b) {
            if ((a instanceof GraphSettings) && (b instanceof GraphSettings))
                return ((GraphSettings) a).getId() == ((GraphSettings) b).getId();
            if ((a instanceof GraphFolder) && (b instanceof GraphFolder))
                return ((GraphFolder) a).getName().equals(((GraphFolder) b).getName());
            return a.equals(b);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionOpen.run();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("rawtypes")
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Iterator it = selection.iterator();
            boolean enabled = false;
            while (it.hasNext()) {
                if (it.next() instanceof GraphSettings) {
                    enabled = true;
                    break;
                }
            }
            actionOpen.setEnabled(enabled);
            actionDelete.setEnabled(enabled);
            actionProperties.setEnabled(enabled);
        }
    });
    filter = new GraphTreeFilter();
    viewer.addFilter(filter);
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getTree().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    activateContext();
    createActions();
    contributeToActionBars();
    createPopupMenu();
    reloadGraphList();
    session.addListener(this);
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) GraphFolder(org.netxms.ui.eclipse.perfview.views.helpers.GraphFolder) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IElementComparer(org.eclipse.jface.viewers.IElementComparer) GraphTreeContentProvider(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeContentProvider) GraphTreeLabelProvider(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeLabelProvider) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GraphSettings(org.netxms.client.datacollection.GraphSettings) GraphTreeFilter(org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeFilter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) FilterText(org.netxms.ui.eclipse.widgets.FilterText) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

Iterator (java.util.Iterator)1 Action (org.eclipse.jface.action.Action)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IElementComparer (org.eclipse.jface.viewers.IElementComparer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 GraphSettings (org.netxms.client.datacollection.GraphSettings)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1 GraphFolder (org.netxms.ui.eclipse.perfview.views.helpers.GraphFolder)1 GraphTreeContentProvider (org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeContentProvider)1 GraphTreeFilter (org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeFilter)1 GraphTreeLabelProvider (org.netxms.ui.eclipse.perfview.views.helpers.GraphTreeLabelProvider)1