Skip to content

06. FAQ

Emre Akkaya edited this page Dec 19, 2016 · 1 revision

This wiki is for developers who wish to get familiar with Lider Console quickly.

I want to create profile dialog, how can I create one?

I want to create task dialog, how can I do this?

I created a task dialog, but I also want to listen to task results, how to achieve this?

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

...

How can I align widgets horizontally (or vertically)?

How can I create a Label widget with bold text?

Label label = new Label(composite, SWT.NONE);
label.setFont(SWTResourceManager.getFont("Sans", 9, SWT.BOLD));

I have a GridLayout with 2 columns, how can I create an empty column/space?

Label without text forms an empty column so just use new Label(composite, SWT.NONE)

How can I create a widget with static height (or width)?

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);

Is there a GUI utility (helper) class that I can use?

We use SWTResourceManager.java class for GUI-related stuff. You can (and should) use its helper methods to create TableViewer, Image or Font instances.

How can I create an Image or Font?

Here you can create an image:

Image image = SWTResourceManager.getImage(LiderConstants.PLUGIN_IDS.LIDER_CONSOLE_CORE, "icons/32/warning.png");

I want to populate Combo with some custom data, how can I do this?

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);

How can I create Textarea?

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);

How can I create Link?

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

What is exportable table and how can I create one?

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");
    }
});

How to read extension point elements?

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...
    }
}