eaa7892047799c422768c485e7b4a9b6d7abe11a
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2015 Victor Kirhenshtein
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 package org
.netxms
.ui
.eclipse
.objectview
.objecttabs
;
21 import org
.eclipse
.core
.runtime
.IConfigurationElement
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
23 import org
.eclipse
.jface
.viewers
.ISelectionProvider
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.custom
.CTabFolder
;
26 import org
.eclipse
.swt
.custom
.CTabItem
;
27 import org
.eclipse
.swt
.graphics
.Image
;
28 import org
.eclipse
.swt
.layout
.FillLayout
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.ui
.IPluginContribution
;
31 import org
.eclipse
.ui
.part
.ViewPart
;
32 import org
.eclipse
.ui
.plugin
.AbstractUIPlugin
;
33 import org
.netxms
.client
.objects
.AbstractObject
;
36 * Abstract object tab class
38 public abstract class ObjectTab
implements IPluginContribution
40 protected String pluginId
;
43 private ViewPart viewPart
;
44 private CTabFolder tabFolder
;
45 private CTabItem tabItem
;
46 private Composite clientArea
;
47 private AbstractObject object
;
50 private ImageDescriptor icon
;
51 private Image tabImage
;
54 * Read configuration before widget creation
56 * @param ce Eclipse registry configuration element
58 public void configure(IConfigurationElement ce
, ViewPart viewPart
)
60 this.viewPart
= viewPart
;
62 pluginId
= ce
.getContributor().getName();
63 id
= ce
.getAttribute("id"); //$NON-NLS-1$
65 id
= "no_id"; //$NON-NLS-1$
67 name
= ce
.getAttribute("name"); //$NON-NLS-1$
69 name
= "<noname>"; //$NON-NLS-1$
73 order
= Integer
.parseInt(ce
.getAttribute("order"), 10); //$NON-NLS-1$
75 catch(NumberFormatException e
)
77 order
= Integer
.MAX_VALUE
;
80 String path
= ce
.getAttribute("icon"); //$NON-NLS-1$
83 icon
= AbstractUIPlugin
.imageDescriptorFromPlugin(ce
.getContributor().getName(), path
);
88 * Create object tab. Intended to be called only by TabbedObjectView.
90 * @param tabFolder Parent tab folder
91 * @param ce Configuration element
93 public void create(final CTabFolder tabFolder
)
95 this.tabFolder
= tabFolder
;
96 clientArea
= new Composite(tabFolder
, SWT
.NONE
);
97 clientArea
.setLayout(new FillLayout());
98 createTabContent(clientArea
);
99 clientArea
.setVisible(false);
103 * Create tab's content.
105 * @param parent Parent composite
107 protected abstract void createTabContent(Composite parent
);
110 * Called by framework when tab is selected.
112 public void selected()
114 clientArea
.moveAbove(null);
116 // sometimes recursive activation can happen when tab selection changed - it's OK here
119 clientArea
.setFocus();
121 catch(RuntimeException e
)
127 * Test if tab should be shown for given NetXMS object. Default implementation always returns true.
129 * @param object Object to test
130 * @return Should return true if tab must be shown for given object
132 public boolean showForObject(final AbstractObject object
)
138 * Called by parent view to inform tab that currently selected object was changed.
140 * @param object New object to display
142 public abstract void objectChanged(AbstractObject object
);
145 * Change current object. Intended to be called only by parent view.
147 * @param object New object to display
149 public void changeObject(AbstractObject object
)
151 this.object
= object
;
152 objectChanged(object
);
156 * Called by parent view to inform tab that update notification for
157 * current object was received from server. Default implementation do nothing.
158 * This method always called in UI thread.
160 * @param object new instance of current object
162 public void currentObjectUpdated(AbstractObject object
)
173 // Find insertion point
174 int index
= tabFolder
.getItemCount();
175 for(int i
= 0; i
< tabFolder
.getItemCount(); i
++)
177 ObjectTab tab
= (ObjectTab
)tabFolder
.getItem(i
).getData();
178 if (tab
.getOrder() > order
)
185 tabItem
= new CTabItem(tabFolder
, SWT
.NONE
, index
);
186 tabItem
.setText(name
);
189 tabImage
= icon
.createImage();
190 tabItem
.setImage(tabImage
);
192 tabItem
.setControl(clientArea
);
193 tabItem
.setData(this);
194 clientArea
.setVisible(true);
201 public String
getName()
213 tabItem
.setControl(null);
214 // sometimes recursive activation can happen when we hide unneeded tabs - it's OK here
219 catch(RuntimeException e
)
223 if (tabImage
!= null)
228 clientArea
.setVisible(false);
233 * Check if this tab is currently visible
237 public final boolean isVisible()
239 return tabItem
!= null;
243 * Check if this tab is currently active
247 public final boolean isActive()
249 return tabFolder
.getSelection() == tabItem
;
253 * Get currently selected object.
255 * @return Currently selected object
257 public AbstractObject
getObject()
265 public int getOrder()
271 * @return the viewPart
273 public ViewPart
getViewPart()
281 * This is the last method called on the ObjectTab. There is no guarantee that createTabContent() has been called,
282 * so the tab controls may never have been created.
284 * Within this method a tab may release any resources, fonts, images, etc. held by this tab. It is also very
285 * important to deregister all listeners from the workbench.
287 * Clients should not call this method (the tab manager calls this method at appropriate times).
289 public void dispose()
291 if (tabImage
!= null)
299 * @return the clientArea
301 protected Composite
getClientArea()
307 * Called by tab manager when user press refresh button in tab view.
308 * Default implementation do nothing.
310 public void refresh()
315 * Get selection provider on tab, if any. If there are no selection provider
316 * on tab, must return null. Default implementation returns null.
318 * @return selection provider on tab
320 public ISelectionProvider
getSelectionProvider()
326 * @see org.eclipse.ui.IPluginContribution#getLocalId()
329 public String
getLocalId()
335 * @see org.eclipse.ui.IPluginContribution#getPluginId()
338 public String
getPluginId()