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;
}
}
}
}
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;
}
});
}
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);
}
}
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();
}
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();
}
Aggregations