use of org.eclipse.jface.viewers.ICheckStateListener in project jbosstools-hibernate by jbosstools.
the class ExporterSettingsTab method createExporterTable.
private void createExporterTable(Composite parent) {
exporterUpDown = new UpDownListComposite(parent, SWT.NONE, HibernateConsoleMessages.ExporterSettingsTab_exporters, true, new ExporterLabelProvider(), new ExporterContentProvider()) {
protected Object[] handleAdd(int idx) {
switch(idx) {
case 0:
Object[] selectExporters = selectExporters(getShell(), HibernateConsoleMessages.ExporterSettingsTab_add_exporter, HibernateConsoleMessages.ExporterSettingsTab_select_exporter_you_want_to_add);
for (int i = 0; i < selectExporters.length; i++) {
ExporterDefinition exporterDefinition = (ExporterDefinition) selectExporters[i];
addDef(exporterDefinition);
}
// { exporterFactory };
return new Object[0];
case 1:
getExporterTable().setAllChecked(true);
selectedExporters.clear();
observableFactoryList.copyUnderlyingList(selectedExporters);
dialogChanged();
break;
case 2:
getExporterTable().setAllChecked(false);
selectedExporters.clear();
dialogChanged();
break;
default:
break;
}
return null;
}
private void addDef(ExporterDefinition expDef) {
int initialCount = getTable().getItemCount();
boolean duplicate = false;
do {
duplicate = false;
initialCount++;
for (ExporterFactory def : observableFactoryList.getList()) {
if (def.getId().equals("" + initialCount)) {
// $NON-NLS-1$
duplicate = true;
}
}
} while (duplicate);
// $NON-NLS-1$
String initialName = "" + initialCount;
ExporterFactory exporterFactory = new ExporterFactory(expDef, initialName);
observableFactoryList.add(exporterFactory);
selectedExporters.add(exporterFactory);
((CheckboxTableViewer) getTableViewer()).setChecked(exporterFactory, true);
}
@SuppressWarnings("unchecked")
protected void handleRemove() {
IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
if (selection != null) {
Iterator<Object> iterator = selection.iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
observableFactoryList.remove((ExporterFactory) item);
deletedExporterIds.add(((ExporterFactory) item).getId());
}
// getTableViewer().setSelection(StructuredSelection.EMPTY);
listChanged();
}
}
protected void moveSelectionDown() {
Table table = getTableViewer().getTable();
int[] indices = table.getSelectionIndices();
if (indices.length < 1) {
return;
}
int[] newSelection = new int[indices.length];
int max = table.getItemCount() - 1;
for (int i = indices.length - 1; i >= 0; i--) {
int index = indices[i];
if (index < max) {
ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
observableFactoryList.moveTo(index + 1, data);
newSelection[i] = index + 1;
}
}
table.setSelection(newSelection);
listChanged();
}
protected void moveSelectionUp() {
Table table = getTableViewer().getTable();
int[] indices = table.getSelectionIndices();
int[] newSelection = new int[indices.length];
for (int i = 0; i < indices.length; i++) {
int index = indices[i];
if (index > 0) {
ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
observableFactoryList.moveTo(index - 1, data);
newSelection[i] = index - 1;
}
}
table.setSelection(newSelection);
listChanged();
}
protected String[] getAddButtonLabels() {
return new String[] { HibernateConsoleMessages.ExporterSettingsTab_add, HibernateConsoleMessages.ExporterSettingsTab_select_all, HibernateConsoleMessages.ExporterSettingsTab_deselect_all };
}
protected void listChanged() {
dialogChanged();
}
};
getExporterTable().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
ExporterFactory factory = (ExporterFactory) event.getElement();
if (!event.getChecked() && selectedExporters.contains(factory)) {
selectedExporters.remove(factory);
} else if (event.getChecked() && !selectedExporters.contains(factory)) {
selectedExporters.add(factory);
}
dialogChanged();
}
});
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = GridData.FILL;
gd.horizontalAlignment = GridData.FILL;
exporterUpDown.setLayoutData(gd);
}
use of org.eclipse.jface.viewers.ICheckStateListener in project jbosstools-hibernate by jbosstools.
the class CheckedTreeSelectionDialog method createTreeViewer.
/**
* Creates the tree viewer.
*
* @param parent
* the parent composite
* @return the tree viewer
*/
protected CheckboxTreeViewer createTreeViewer(Composite parent) {
if (fContainerMode) {
fViewer = new ContainerCheckedTreeViewer(parent, SWT.BORDER);
} else {
fViewer = new CheckboxTreeViewer(parent, SWT.BORDER);
}
fViewer.setContentProvider(fContentProvider);
fViewer.setLabelProvider(fLabelProvider);
fViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
updateOKStatus();
}
});
fViewer.setComparator(fComparator);
if (fFilters != null) {
for (int i = 0; i != fFilters.size(); i++) {
fViewer.addFilter((ViewerFilter) fFilters.get(i));
}
}
fViewer.setInput(fInput);
return fViewer;
}
use of org.eclipse.jface.viewers.ICheckStateListener in project erlide_eclipse by erlang.
the class ResourceTreeAndListGroup method notifyCheckStateChangeListeners.
/**
* Notify all checked state listeners that the passed element has had its checked
* state changed to the passed state
*/
protected void notifyCheckStateChangeListeners(final CheckStateChangedEvent event) {
final Object[] array = getListeners();
for (final Object anArray : array) {
final ICheckStateListener l = (ICheckStateListener) anArray;
SafeRunner.run(new SafeRunnable() {
@Override
public void run() {
l.checkStateChanged(event);
}
});
}
}
Aggregations