How to get an Object from a ComboViewer? [message #953456] |
Mon, 22 October 2012 09:04 |
Matthias Bollen Messages: 1 Registered: October 2012 Location: Gießen, Germany |
Junior Member |
|
|
Hello everyone,
currently I try to make a program with JTAPI and XTAPI implementation.
Now I have a problem with the ComboViewer. As you can see on the picture I can see and select the Tapi-line in the comboViewer.
But how can I get or select the object from the comboViewer?
protected void createContents() {
... // the other Shell Components like Buttons and Labels
combo = new Combo(shell, SWT.NONE);
combo.setBounds(2, 10, 181, 23);
comboViewer = new ComboViewer(combo);
comboViewer.setContentProvider(new ArrayContentProvider());
comboViewer.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
return ((Terminal) element).getName();
}
});
comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Terminal selectedObject = (Terminal) selection.getFirstElement();
}
});
// Call the Method initJTapi
initJTapi();
}
private void initJTapi() {
try {
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer("net.xtapi.XJtapiPeer");
// Provider
myprovider = peer.getProvider("net.xtapi.serviceProvider.MSTAPI");
Terminal[] t = myprovider.getTerminals();
// put all (terminal) objects you can find in a list
for (int loop = 0; loop < t.length; loop++) {
liste.add(loop, t[loop]);
}
comboViewer.setInput(liste);
} catch (Exception excp) {
MessageDialog.openInformation(shell, "Warnung", "Can not get a provider.");
}
ISelection selection = comboViewer.getSelection();
if (!selection.isEmpty()) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
// cast the object to an terminal object
m_terminal = (Terminal) structuredSelection.getFirstElement();
}
}
-
Attachment: program.png
(Size: 7.88KB, Downloaded 343 times)
|
|
|
|
Powered by
FUDForum. Page generated in 0.02878 seconds