List of usage examples for org.eclipse.jface.viewers CheckboxTableViewer setCheckedElements
public void setCheckedElements(Object[] elements)
From source file:org.wso2.developerstudio.eclipse.platform.ui.wizard.pages.ProjectOptionsDataPage.java
License:Open Source License
private void createTypeListCheckBoxListField(Composite container, int noOfColumns, final ProjectOptionData optionData) { final CheckboxTableViewer combo = WSO2UIToolkit.createList(container, optionData.getCaption(), noOfColumns, optionData.getVerticalIndent(), optionData.getHorizontalIndent(), optionData.isSelectAllbtn(), this, optionData);// www .j a v a 2s .co m FieldExecutor fieldExecutor = new CommonFieldExecutor(optionData, getModel(), combo.getTable()) { public void validate() throws FieldValidationException { if (optionData.getFieldController() != null) { optionData.getFieldController().validate(optionData.getModelProperty(), combo.getCheckedElements(), getModel()); } } public void setFieldValue(ProjectDataModel model) throws Exception { combo.getTable().removeAll(); List<ListData> listData = optionData.getListDataProvider() .getListData(optionData.getModelProperty(), getModel()); for (ListData data : listData) { TableItem tableItem = new TableItem(combo.getTable(), SWT.NONE); tableItem.setText(data.getCaption()); tableItem.setData(data.getData()); } Object[] comboTextValue = new Object[] {}; Object modelPropertyValueObj = getModelPropertyValue(); if (modelPropertyValueObj != null) { comboTextValue = (Object[]) modelPropertyValueObj; } combo.setCheckedElements(comboTextValue); } }; fieldControllers.put(optionData.getModelProperty(), fieldExecutor); combo.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent arg0) { String modelProperty = optionData.getModelProperty(); Object[] currentModelPropertyValue = (Object[]) getModel().getModelPropertyValue(modelProperty); try { Object[] checkedElements = combo.getCheckedElements(); if (isEqual(currentModelPropertyValue, checkedElements)) { return; } if (getModel().setModelPropertyValue(modelProperty, checkedElements)) { updateField(modelProperty); } } catch (ObserverFailedException e) { LOG.error("ObserverFailed:", e); } catch (Exception e) { LOG.error("An unexpected error has occurred", e); } doPostFieldModificationAction(optionData); } }); try { updateField(optionData.getModelProperty()); } catch (Exception e) { LOG.error("An unexpected error has occurred", e); } }