-
Notifications
You must be signed in to change notification settings - Fork 0
06. FAQ
This wiki is for developers who wish to get familiar with Lider Console quickly.
We create an EventHandler
and subscribe to related-plugin topics in order to get notified for task results:
private IEventBroker eventBroker = (IEventBroker) PlatformUI.getWorkbench().getService(IEventBroker.class);
...
// Sample task dialog constructor
public SampleTaskDialog(Shell parentShell, String dn) {
super(parentShell, dn);
// Here, we subscribe to related-plugin topics
eventBroker.subscribe(getPluginName().toUpperCase(Locale.ENGLISH), eventHandler);
}
...
private EventHandler eventHandler = new EventHandler() {
@Override
public void handleEvent(final Event event) {
Job job = new Job("TASK") {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(getPluginName(), 100);
// Handle task result here!
...
monitor.worked(100);
monitor.done();
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
};
...
Label label = new Label(composite, SWT.NONE);
label.setFont(SWTResourceManager.getFont("Sans", 9, SWT.BOLD));
Label
without text forms an empty column so just use new Label(composite, SWT.NONE)
We can specify the preferred height or width using GridData
such as below:
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.heightHint = 100;
text.setLayoutData(gridData);
We use SWTResourceManager.java class for GUI-related stuff. You can (and should) use its helper methods to create TableViewer
, Image
or Font
instances.
Here you can create an image:
Image image = SWTResourceManager.getImage(LiderConstants.PLUGIN_IDS.LIDER_CONSOLE_CORE, "icons/32/warning.png");
Usually, combo items (options) can be set via combo.setItems()
method but in this case you also need to hold custom data. We can achieve this like the example below:
...
// Sample dummy items and related custom data
private final String[] items = new String[] { "ENABLE", "DISABLE" };
private final String[] customData = new String[] { "1", "0" };
...
Combo combo = new Combo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
combo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
for (int i = 0; i < items.length; i++) {
String i18n = Messages.getString(items[i]);
if (i18n != null && !i18n.isEmpty()) {
// We can also ensure i18n here!
combo.add(i18n);
combo.setData(i + "", customData[i]);
}
}
...
// ...and that's how you can get selected value
int selectionIndex = combo.getSelectionIndex();
if (selectionIndex > -1 && combo.getItem(selectionIndex) != null
&& combo.getData(selectionIndex + "") != null) {
return combo.getData(selectionIndex + "").toString();
}
...
I want to read something from Lider Console properties file config.properties, how do I access this file?
We use ConfigProvider
to access the properties, an example is given below:
// LiderConstants.CONFIG contains all property names!
ConfigProvider.getInstance().getInt(LiderConstants.CONFIG.REST_CONN_REQUEST_TIMEOUT));
ConfigProvider.getInstance().getStringArr(LiderConstants.CONFIG.USER_LDAP_OBJ_CLS);
Textarea is just a Text
widget with some static height:
Text text = new Text(parent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.heightHint = 100;
text.setLayoutData(gridData);
Link link = new Link(parent, SWT.NONE);
link.setText(Messages.getString("LINK_MESSAGE"));
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
} catch (PartInitException e1) {
logger.error(e1.getMessage(), e1);
} catch (MalformedURLException e2) {
logger.error(e2.getMessage(), e2);
}
}
});
We can create an 'exportable' table so that users can export excel (.XLSX) report from a tableviewer. Here is how to do that:
TableViewer tableViewer = SWTResourceManager.createTableViewer(parent, new IExportableTableViewer() {
@Override
public Composite getButtonComposite() {
// export button will be placed in this composite!
return buttonComposite;
}
@Override
public String getSheetName() {
return Messages.getString("YOUR_SHEET_NAME");
}
@Override
public String getReportName() {
return Messages.getString("YOUR_REPORT_NAME");
}
});
Plugins can contribute to different extension points in their plugin.xml files. Please refer to this class for a full list of extension points.
In order to read extension point elements contributed by plugins, we use extension registry like this:
IExtensionRegistry registry = Platform.getExtensionRegistry();
IExtensionPoint extensionPoint = registry.getExtensionPoint(LiderConstants.EXTENSION_POINTS.I18N);
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
if (elements != null) {
for (IConfigurationElement element : elements) {
// do something...
}
}