Search in sources :

Example 1 with ObjectTab

use of org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab in project netxms by netxms.

the class TabbedObjectView method selectTab.

/**
 * Select tab with given ID
 *
 * @param tabId
 */
public void selectTab(String tabId) {
    if (tabId != null) {
        for (int i = 0; i < tabFolder.getItemCount(); i++) {
            CTabItem item = tabFolder.getItem(i);
            ObjectTab tab = (ObjectTab) item.getData();
            if (tab.getLocalId().equals(tabId)) {
                tabFolder.setSelection(i);
                onTabSelectionChange(tab);
                break;
            }
        }
    }
}
Also used : CTabItem(org.eclipse.swt.custom.CTabItem) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab)

Example 2 with ObjectTab

use of org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab in project netxms by netxms.

the class TabbedObjectView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    parent.setLayout(layout);
    headerFont = FontTools.createFont(HEADER_FONTS, +3, SWT.BOLD);
    header = new CLabel(parent, SWT.BORDER);
    header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    header.setFont(headerFont);
    header.setBackground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER_BACKGROUND, parent.getDisplay()));
    header.setForeground(SharedColors.getColor(SharedColors.OBJECT_TAB_HEADER, parent.getDisplay()));
    tabFolder = new CTabFolder(parent, SWT.TOP | SWT.FLAT | SWT.MULTI);
    tabFolder.setUnselectedImageVisible(true);
    tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tabFolder.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onTabSelectionChange((e.item != null) ? (ObjectTab) ((CTabItem) e.item).getData() : null);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    tabs = new ArrayList<ObjectTab>();
    addTabs();
    selectionListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (// $NON-NLS-1$
            (part.getSite().getId().equals("org.netxms.ui.eclipse.view.navigation.objectbrowser")) && (selection instanceof IStructuredSelection)) {
                if (selection.isEmpty()) {
                    setObject(null);
                } else {
                    Object object = ((IStructuredSelection) selection).getFirstElement();
                    if (object instanceof AbstractObject) {
                        setObject((AbstractObject) object);
                    }
                }
            }
        }
    };
    selectionService.addPostSelectionListener(selectionListener);
    createActions();
    contributeToActionBars();
    selectionProvider = new IntermediateSelectionProvider();
    getSite().setSelectionProvider(selectionProvider);
    final NXCSession session = ConsoleSharedData.getSession();
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if ((n.getCode() == SessionNotification.OBJECT_CHANGED) && (objectId == n.getSubCode())) {
                final AbstractObject object = (AbstractObject) n.getObject();
                getSite().getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        onObjectUpdate(object);
                    }
                });
            }
        }
    };
    session.addListener(sessionListener);
    CommandBridge.getInstance().registerCommand("TabbedObjectView/selectTab", new // $NON-NLS-1$
    Command() {

        @Override
        public Object execute(String name, Object arg) {
            if (arg instanceof String)
                selectTab((String) arg);
            return null;
        }
    });
    CommandBridge.getInstance().registerCommand("TabbedObjectView/changeObject", new // $NON-NLS-1$
    Command() {

        @Override
        public Object execute(String name, Object arg) {
            if (arg instanceof Long)
                setObject(session.findObjectById((Long) arg));
            return null;
        }
    });
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) IntermediateSelectionProvider(org.netxms.ui.eclipse.tools.IntermediateSelectionProvider) CTabFolder(org.eclipse.swt.custom.CTabFolder) NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CTabItem(org.eclipse.swt.custom.CTabItem) ISelectionListener(org.eclipse.ui.ISelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) AbstractObject(org.netxms.client.objects.AbstractObject) SessionListener(org.netxms.client.SessionListener) SessionNotification(org.netxms.client.SessionNotification) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab) ISelectionListener(org.eclipse.ui.ISelectionListener) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with ObjectTab

use of org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab in project netxms by netxms.

the class TabbedObjectView method addTabs.

/**
 * Add all tabs
 */
private void addTabs() {
    // Read all registered extensions and create tabs
    final IExtensionRegistry reg = Platform.getExtensionRegistry();
    // $NON-NLS-1$
    IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.objectview.tabs");
    for (int i = 0; i < elements.length; i++) {
        try {
            // $NON-NLS-1$
            final ObjectTab tab = (ObjectTab) elements[i].createExecutableExtension("class");
            tab.configure(elements[i], this);
            tabs.add(tab);
        } catch (CoreException e) {
            // $NON-NLS-1$
            Activator.log("Exception when instantiating object tab", e);
        }
    }
    // Sort tabs by appearance order
    Collections.sort(tabs, new Comparator<ObjectTab>() {

        @Override
        public int compare(ObjectTab arg0, ObjectTab arg1) {
            return arg0.getOrder() - arg1.getOrder();
        }
    });
    // Create widgets for all tabs
    for (final ObjectTab tab : tabs) {
        tab.create(tabFolder);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 4 with ObjectTab

use of org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab in project netxms by netxms.

the class TabbedObjectView method dispose.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
	 */
@Override
public void dispose() {
    ConsoleSharedData.getSession().removeListener(sessionListener);
    // $NON-NLS-1$
    CommandBridge.getInstance().unregisterCommand("TabbedObjectView/selectTab");
    // $NON-NLS-1$
    CommandBridge.getInstance().unregisterCommand("TabbedObjectView/changeObject");
    ConsoleSharedData.getSession().removeListener(sessionListener);
    if (sourceProvider != null)
        sourceProvider.updateProperty(SourceProvider.ACTIVE_TAB, null);
    getSite().setSelectionProvider(null);
    if ((selectionService != null) && (selectionListener != null))
        selectionService.removePostSelectionListener(selectionListener);
    for (final ObjectTab tab : tabs) {
        tab.dispose();
    }
    headerFont.dispose();
    super.dispose();
}
Also used : ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab)

Example 5 with ObjectTab

use of org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab in project netxms by netxms.

the class TabbedObjectView method setObjectInternal.

/**
 * Set new active object - internal implementation
 *
 * @param object New object
 */
private void setObjectInternal(AbstractObject object) {
    Control focusControl = Display.getCurrent().getFocusControl();
    if (object != null) {
        header.setText(object.getObjectName());
        for (final ObjectTab tab : tabs) {
            if (tab.showForObject(object) && !WorkbenchActivityHelper.filterItem(tab)) {
                tab.show();
                tab.changeObject(object);
            } else {
                if (tab == activeTab)
                    tab.unselected();
                tab.hide();
                tab.changeObject(null);
            }
        }
        if ((objectId == 0) || (tabFolder.getSelection() == null)) {
            try {
                tabFolder.setSelection(0);
                ObjectTab tab = (ObjectTab) tabFolder.getItem(0).getData();
                onTabSelectionChange(tab);
            } catch (IllegalArgumentException e) {
            }
        }
        objectId = (object != null) ? object.getObjectId() : 0;
    } else {
        for (final ObjectTab tab : tabs) {
            tab.hide();
            tab.changeObject(null);
        }
        objectId = 0;
        // $NON-NLS-1$
        header.setText("");
    }
    if (focusControl != null)
        focusControl.setFocus();
}
Also used : Control(org.eclipse.swt.widgets.Control) ObjectTab(org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab)

Aggregations

ObjectTab (org.netxms.ui.eclipse.objectview.objecttabs.ObjectTab)5 CTabItem (org.eclipse.swt.custom.CTabItem)2 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CLabel (org.eclipse.swt.custom.CLabel)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Control (org.eclipse.swt.widgets.Control)1 ISelectionListener (org.eclipse.ui.ISelectionListener)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 NXCSession (org.netxms.client.NXCSession)1 SessionListener (org.netxms.client.SessionListener)1 SessionNotification (org.netxms.client.SessionNotification)1 AbstractObject (org.netxms.client.objects.AbstractObject)1