import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.help.WorkbenchHelp;
+import org.eclipse.ui.PlatformUI;
/**
- *
+ *
*/
public class BrowserTableComposite extends Composite {
protected Table table;
protected Button remove;
protected Button search;
protected IWebBrowser selection;
-
+
protected Label location;
protected Label parameters;
-
+
public BrowserTableComposite(Composite parent, int style) {
super(parent, style);
createWidgets();
GridData data = new GridData(GridData.FILL_BOTH);
setLayoutData(data);
-
+
Label label = new Label(this, SWT.NONE);
label.setText(WebBrowserUIPlugin.getResource("%browserList"));
data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
data.horizontalSpan = 2;
label.setLayoutData(data);
-
+
table = new Table(this, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
data.widthHint = 300;
table.setLayoutData(data);
table.setHeaderVisible(false);
table.setLinesVisible(false);
-
+
TableLayout tableLayout = new TableLayout();
new TableColumn(table, SWT.NONE);
-
+
tableLayout.addColumnData(new ColumnWeightData(100));
table.setLayout(tableLayout);
-
+
tableViewer = new CheckboxTableViewer(table);
-
+
tableViewer.setContentProvider(new BrowserContentProvider());
tableViewer.setLabelProvider(new BrowserTableLabelProvider());
-
+
tableViewer.setInput("root");
// uncheck any other elements that might be checked and leave only the element checked to
checkNewDefaultBrowser(e.getElement());
IWebBrowser browser = (IWebBrowser) e.getElement();
BrowserManager.getInstance().setCurrentWebBrowser(browser);
-
+
// if no other browsers are checked, don't allow the single one currently
// checked to become unchecked, and lose a current browser. That is, don't
// permit unchecking if no other item is checked which is supposed to be the case.
tableViewer.setChecked(e.getElement(), true);
}
});
-
+
// set a default, checked browser based on the current browser. If there is not a
// current browser, but the first item exists, use that instead.
// This will work currently until workbench shutdown, because current browser is not yet persisted.
if (obj != null)
tableViewer.setChecked(obj, true);
}
-
+
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
Object obj = getSelection(event.getSelection());
-
+
if (obj instanceof IInternalWebBrowser) {
selection = (IInternalWebBrowser) obj;
remove.setEnabled(false);
edit.setEnabled(true);
} else
selection = null;
-
+
if (selection == null) {
edit.setEnabled(false);
remove.setEnabled(false);
}
}
});
-
+
Composite buttonComp = new Composite(this, SWT.NONE);
layout = new GridLayout();
layout.horizontalSpacing = 0;
buttonComp.setLayout(layout);
data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL);
buttonComp.setLayoutData(data);
-
+
Button add = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%add"));
add.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
tableViewer.refresh();
}
});
-
+
edit = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%edit"));
edit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
tableViewer.refresh(wc.save());
} catch (Exception ex) { }
}
- }
+ }
else if(browser2 instanceof IExternalWebBrowser) {
IExternalWebBrowserWorkingCopy wc = ((IExternalWebBrowser) browser2).getWorkingCopy();
ExternalBrowserDialog dialog = new ExternalBrowserDialog(getShell(), wc);
} catch (Exception ex) { }
}
}
- }
+ }
});
edit.setEnabled(false);
if (browser2 instanceof IInternalWebBrowser){
remove.setEnabled(false);
return; // nothing else possible to do
- }
+ }
else if(browser2 instanceof IExternalWebBrowser) {
remove.setEnabled(true);
((IExternalWebBrowser) browser2).delete();
-
+
tableViewer.remove(browser2);
-
+
// need here to ensure that if the item deleted was checked, ie, was
// the current browser, that the new current browser will be the first in the
// list, typically, the internal browser, which cannot be deleted, and be current.
}
});
remove.setEnabled(false);
-
+
search = SWTUtil.createButton(buttonComp, WebBrowserUIPlugin.getResource("%search"));
search.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
java.util.List browsersToCreate = BrowserSearcher.search(getShell());
-
+
if (browsersToCreate == null) // cancelled
return;
-
+
if (browsersToCreate.isEmpty()) { // no browsers found
WebBrowserUtil.openMessage(WebBrowserUIPlugin.getResource("%searchingNoneFound"));
return;
}
-
+
Iterator iterator = browsersToCreate.iterator();
while (iterator.hasNext()) {
IExternalWebBrowserWorkingCopy browser2 = (IExternalWebBrowserWorkingCopy) iterator.next();
tableViewer.refresh();
}
});
- WorkbenchHelp.setHelp(search, ContextIds.PREF_BROWSER_EXTERNAL_SEARCH);
-
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(search, ContextIds.PREF_BROWSER_EXTERNAL_SEARCH);
+
tableViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
checkNewDefaultBrowser(e.getElement());
});
search.setEnabled(true);
}
-
+
public IWebBrowser getSelectedWebBrowser() {
return selection;
}
-
+
protected Object getSelection(ISelection sel2) {
IStructuredSelection sel = (IStructuredSelection) sel2;
return sel.getFirstElement();
}
-
+
// Uncheck all the items except the current one that was just checked
protected void checkNewDefaultBrowser(Object browser) {
TableItem[] children = tableViewer.getTable().getItems();
for (int i = 0; i < children.length; i++) {
TableItem item = children[i];
-
- if (!(item.getData().equals(browser)))
+
+ if (!(item.getData().equals(browser)))
item.setChecked(false);
}
}