/**
* Action.
*
* @param arg0
* @return
*/
private boolean actionCellSelected(CellSelectionEvent arg0) {
// Reset
this.selectedColumn = null;
this.selectedRow = null;
// Set
int column = arg0.getColumnPosition();
int row = arg0.getRowPosition();
if (column>=0 && row>=0 && row<dataProviderBody.getRowCount() && column<dataProviderBody.getColumnCount()){
this.selectedColumn = column;
this.selectedRow = row;
fireSelectionEvent();
return true;
} else {
return false;
}
}
/**
* Adds a selection listener.
*
* @param layer
*/
private void addSelectionListener(final SelectionLayer layer) {
layer.addLayerListener(new ILayerListener(){
@Override
public void handleLayerEvent(ILayerEvent arg0) {
if (arg0 instanceof CellSelectionEvent) {
if (!actionCellSelected((CellSelectionEvent)arg0)){
layer.clear(true);
}
} else if (arg0 instanceof ColumnSelectionEvent) {
if (!actionColumnSelected((ColumnSelectionEvent)arg0)){
layer.clear(true);
}
} else if (arg0 instanceof RowSelectionEvent) {
if (!actionRowSelected((RowSelectionEvent)arg0)) {
layer.clear(true);
}
}
}
});
}
/**
* Cell selection event.
*
* @param arg1
*/
protected void actionCellSelected(CellSelectionEvent arg1){
if (model != null) {
int column = arg1.getColumnPosition() - 1;
if (column>=0) actionColumnSelected(column);
}
}
@Override
protected void actionCellSelected(CellSelectionEvent arg1) {
super.actionCellSelected(arg1);
}
/**
*
* Creates a new data view.
*
* @param parent
* @param controller
* @param title
* @param helpid
*/
public ViewData(final Composite parent,
final Controller controller,
final String helpid,
final String title) {
// Register
controller.addListener(ModelPart.ATTRIBUTE_TYPE, this);
controller.addListener(ModelPart.ATTRIBUTE_TYPE_BULK_UPDATE, this);
controller.addListener(ModelPart.SELECTED_ATTRIBUTE, this);
controller.addListener(ModelPart.MODEL, this);
controller.addListener(ModelPart.OUTPUT, this);
controller.addListener(ModelPart.SELECTED_VIEW_CONFIG, this);
controller.addListener(ModelPart.INPUT, this);
// Store
this.controller = controller;
// Load images
IMAGE_ASCENDING = controller.getResources().getManagedImage("sort_ascending.png"); //$NON-NLS-1$
IMAGE_DESCENDING = controller.getResources().getManagedImage("sort_descending.png");//$NON-NLS-1$
// Create title bar
ComponentTitledFolderButtonBar bar = new ComponentTitledFolderButtonBar(helpid, helpids); //$NON-NLS-1$
bar.add(Resources.getMessage("DataView.1"), //$NON-NLS-1$
IMAGE_ASCENDING,
new Runnable() {
@Override
public void run() {
model.getViewConfig().setSortOrder(true);
actionSort();
}
});
bar.add(Resources.getMessage("DataView.4"), //$NON-NLS-1$
IMAGE_DESCENDING,
new Runnable() {
@Override
public void run() {
model.getViewConfig().setSortOrder(false);
actionSort();
}
});
bar.add(Resources.getMessage("DataView.2"), //$NON-NLS-1$
controller.getResources().getManagedImage("sort_groups.png"), //$NON-NLS-1$
new Runnable() {
@Override
public void run() {
controller.actionDataShowGroups();
}
});
bar.add(Resources.getMessage("DataView.3"), //$NON-NLS-1$
controller.getResources().getManagedImage("sort_subset.png"), //$NON-NLS-1$
true,
new Runnable() {
@Override
public void run() {
controller.actionDataToggleSubset();
}
});
// Build border
folder = new ComponentTitledFolder(parent, controller, bar, null);
folder.setLayoutData(SWTUtil.createFillGridData());
Composite c = folder.createItem(title, null);
folder.setSelection(0);
GridLayout l = new GridLayout();
l.numColumns = 1;
c.setLayout(l);
// Build table
table = new ComponentDataTable(controller, c);
table.addSelectionLayerListener(new ILayerListener(){
@Override
public void handleLayerEvent(ILayerEvent arg0) {
if (arg0 instanceof CellSelectionEvent) {
actionCellSelected((CellSelectionEvent)arg0);
} else if (arg0 instanceof ColumnSelectionEvent) {
actionColumnSelected((ColumnSelectionEvent)arg0);
}
}
});
// Build buttons
this.groupsButton = folder.getButtonItem(Resources.getMessage("DataView.2")); //$NON-NLS-1$
this.groupsButton.setEnabled(false);
this.subsetButton = folder.getButtonItem(Resources.getMessage("DataView.3")); //$NON-NLS-1$
this.subsetButton.setEnabled(false);
this.ascendingButton = folder.getButtonItem(Resources.getMessage("DataView.1")); //$NON-NLS-1$
this.ascendingButton.setEnabled(false);
this.descendingButton = folder.getButtonItem(Resources.getMessage("DataView.4")); //$NON-NLS-1$
this.descendingButton.setEnabled(false);
}