import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.nebula.widgets.nattable.NatTable;
+import org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand;
import org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration;
import org.eclipse.nebula.widgets.nattable.config.CellConfigAttributes;
import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry;
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
+import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsSortModel;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeData;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.tree.GlazedListTreeRowModel;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
import org.eclipse.nebula.widgets.nattable.reorder.RowReorderLayer;
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
import org.eclipse.nebula.widgets.nattable.selection.event.CellSelectionEvent;
+import org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer;
+import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
import org.eclipse.nebula.widgets.nattable.style.DisplayMode;
import org.eclipse.nebula.widgets.nattable.summaryrow.FixedSummaryRowLayer;
import org.eclipse.nebula.widgets.nattable.summaryrow.SummaryRowLayer;
private WorkingSet workingSet;
- private Composite parent;
-
private ConversationHolder conversation;
private ICdmEntitySession cdmEntitySession;
private ListDataProvider<Object> bodyDataProvider;
+ private Label wsLabel;
+
+ private Button btnToggleTree;
+
+ private Button btnToggleFlat;
+
+ private Button btnCollapseAll;
+
+ private Button btnExpandAll;
+
+ private ComboViewer comboStates;
+
+ private Button btnManageState;
+
+ private Button btnExcelExport;
+
+ private Composite buttonPanel;
+
+ private Composite parent;
+
+ private List<Feature> features;
+
@PostConstruct
public void create(Composite parent) {
if(CdmStore.isActive() && conversation==null){
else{
return;
}
- parent.setLayout(new GridLayout());
this.parent = parent;
- }
+ parent.setLayout(new GridLayout());
+ Composite toolbarComposite = new Composite(parent, SWT.NONE);
+ toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ toolbarComposite.setLayout(new GridLayout(8, false));
+ natTable = new NatTable(parent, false);
- public void init(UUID workingSetUuid) {
- this.workingSet = CdmStore.getService(IWorkingSetService.class).load(workingSetUuid, WS_PROPERTY_PATH);
- if(workingSet.getDescriptiveSystem()==null){
- MessagingUtils.informationDialog("Editor could not be opened", "The working set has no feature tree selected.");
- return;
+ wsLabel = new Label(toolbarComposite, SWT.NONE);
+
+ btnToggleTree = new Button(toolbarComposite, SWT.PUSH);
+ btnToggleFlat = new Button(toolbarComposite, SWT.PUSH);
+ btnCollapseAll = new Button(toolbarComposite, SWT.PUSH);
+ btnExpandAll = new Button(toolbarComposite, SWT.PUSH);
+ comboStates = new ComboViewer(toolbarComposite, SWT.DROP_DOWN);
+ btnManageState = new Button(toolbarComposite, SWT.PUSH);
+ btnExcelExport = new Button(toolbarComposite, SWT.PUSH);
+
+ /**
+ * Toogle tree button
+ */
+ btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL));
+ btnToggleTree.setToolTipText("Show taxon hierarchy");
+ btnToggleTree.setSelection(true);
+ btnToggleTree.setEnabled(false);
+ btnToggleTree.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ toggleTreeFlat(true);
+ }
+ });
+
+ /**
+ * Toogle flat button
+ */
+ btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT));
+ btnToggleFlat.setToolTipText("Show flat list");
+ btnToggleFlat.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ toggleTreeFlat(false);
+ }
+ });
+
+ /**
+ *
+ * Collapse button
+ */
+ btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL));
+ btnCollapseAll.setToolTipText("Collapse all");
+ btnCollapseAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ natTable.doCommand(new TreeCollapseAllCommand());
+ }
+ });
+
+ /**
+ * Expand button
+ */
+ btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL));
+ btnExpandAll.setToolTipText("Expand all");
+ btnExpandAll.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ natTable.doCommand(new TreeExpandAllCommand());
+ }
+ });
+
+ /**
+ * Table state persistence
+ */
+ natTableState = new Properties();
+ //load persisted state
+ File statePropertiesFile = getStatePropertiesFile();
+ FileInputStream inputStream;
+ try {
+ inputStream = new FileInputStream(statePropertiesFile);
+ natTableState.load(inputStream);
+ } catch (IOException e) {
+ MessagingUtils.info("No initial state properties file found for character matrix");
}
- thisPart.setLabel(workingSet.getLabel());
- Composite toolbarComposite = new Composite(parent, SWT.NONE);
- toolbarComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- toolbarComposite.setLayout(new GridLayout(6, false));
+ DisplayPersistenceDialogCommandHandler handler =
+ new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
+ natTable.registerCommandHandler(handler);
+ // create a combobox for showing the available view states
+ Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState);
+ comboStates.setLabelProvider(new LabelProvider(){
+ @Override
+ public String getText(Object element) {
+ if(element instanceof String && ((String) element).isEmpty()){
+ return "-default-";
+ }
+ return super.getText(element);
+ }
+ });
+ comboStates.setContentProvider(new ArrayContentProvider());
+ comboStates.addSelectionChangedListener(e->
+ {
+ int index = comboStates.getCombo().getSelectionIndex();
+ if (index >= 0) {
+ String selected = comboStates.getCombo().getItem(index);
+ // load the state
+ natTable.loadState(selected, natTableState);
+ natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected);
+ }
+ });
+ comboStates.setInput(availableStates);
+ if(comboStates.getCombo().getItemCount()>0){
+ comboStates.getCombo().select(0);
+ }
+
+ // add listener to update the combo on view state management changes
+ handler.addStateChangeListener(new IStateChangedListener() {
+ @Override
+ public void handleStateChange(StateChangeEvent event) {
+ comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState));
+ selectStateItem(comboStates, event.getViewConfigName());
+ }
+ });
+
+ // add button to show dialog
+ btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
+ btnManageState.setToolTipText("View configuration");
+ btnManageState.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
+ selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString());
+ }
+ });
+
+ /**
+ * excel export
+ */
+ btnExcelExport.setToolTipText("Export to Excel");
+ btnExcelExport.setImage(ImageResources.getImage(ImageResources.EXPORT));
+ btnExcelExport.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ natTable.doCommand(
+ new ExportCommand(
+ natTable.getConfigRegistry(),
+ natTable.getShell()));
+ }
+ });
+
+ buttonPanel = new Composite(parent, SWT.NONE);
+ }
+
+ private void toggleTreeFlat(boolean isTree) {
+ init(workingSet.getUuid(), isTree);
+ btnToggleFlat.setEnabled(isTree);
+ btnToggleTree.setEnabled(!isTree);
+ btnCollapseAll.setEnabled(isTree);
+ btnExpandAll.setEnabled(isTree);
+ natTable.doCommand(new StructuralRefreshCommand());
+ }
+
+ public void init(UUID workingSetUuid, boolean treeView) {
+ if(workingSet==null){
+ this.workingSet = CdmStore.getService(IWorkingSetService.class).load(workingSetUuid, WS_PROPERTY_PATH);
+ if(workingSet.getDescriptiveSystem()==null){
+ MessagingUtils.informationDialog("Editor could not be opened", "The working set has no feature tree selected.");
+ return;
+ }
+ thisPart.setLabel(workingSet.getLabel());
- //get features/columns stored in working set
- FeatureTree tree = workingSet.getDescriptiveSystem();
- List<Feature> features = new ArrayList<>(tree.getDistinctFeatures());
- Collections.sort(features);
+ //get features/columns stored in working set
+ FeatureTree tree = workingSet.getDescriptiveSystem();
+ features = new ArrayList<>(tree.getDistinctFeatures());
+ Collections.sort(features);
- descriptions = GlazedLists.eventList(getDescriptions(workingSet));
+ descriptions = GlazedLists.eventList(getDescriptions(workingSet));
+ }
// use the SortedList constructor with 'null' for the Comparator
// because the Comparator will be set by configuration
SortedList<Object> sortedList = new SortedList<>(descriptions, null);
// wrap the SortedList with the TreeList
- TreeList treeList = new TreeList(sortedList, new DescriptionTreeFormat(workingSet.getMaxRank()), TreeList.NODES_START_EXPANDED);
-
- ConfigRegistry configRegistry = new ConfigRegistry();
-
+ TreeList<Object> treeList = new TreeList(sortedList, new DescriptionTreeFormat(workingSet.getMaxRank()), TreeList.NODES_START_EXPANDED);
/**
* data provider
*/
SpecimenColumnPropertyAccessor columnPropertyAccessor = new SpecimenColumnPropertyAccessor(this);
- bodyDataProvider = new ListDataProvider<Object>(treeList, columnPropertyAccessor);
+ bodyDataProvider = treeView?new ListDataProvider<>(treeList, columnPropertyAccessor):new ListDataProvider<>(sortedList, columnPropertyAccessor);
+
+ ConfigRegistry configRegistry = new ConfigRegistry();
+
/**
* BODY layer
ViewportLayer
^
- TreeLayer
+ TreeLayer (default visible)
^
SelectionLayer
RowHideShowLayer rowHideShowLayer = new RowHideShowLayer(columnHideShowLayer);
SelectionLayer selectionLayer = new SelectionLayer(rowHideShowLayer);
TreeLayer treeLayer = new TreeLayer(selectionLayer, treeRowModel);
- ViewportLayer viewportLayer = new ViewportLayer(treeLayer);
+ ViewportLayer viewportLayer = treeView?new ViewportLayer(treeLayer):new ViewportLayer(selectionLayer);
// create a standalone FixedSummaryRowLayer
// since the summary row should be fixed at the top of the body
// add the SortHeaderLayer to the column header layer stack
// as we use GlazedLists, we use the GlazedListsSortModel which
// delegates the sorting to the SortedList
- //TODO currently disabled sorting because of tree list
-// final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
-// columnHeaderLayer,
-// new GlazedListsSortModel<>(
-// sortedList,
-// columnPropertyAccessor,
-// configRegistry,
-// columnHeaderDataLayer));
+ final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
+ columnHeaderLayer,
+ new GlazedListsSortModel<>(
+ sortedList,
+ columnPropertyAccessor,
+ configRegistry,
+ columnHeaderDataLayer));
/**
*/
ILayer cornerLayer = new CornerLayer(
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
- fixedSummaryRowHeaderLayer, columnHeaderLayer);
+ fixedSummaryRowHeaderLayer, sortHeaderLayer);
/**
* GRID layer (composition of all other layers)
*/
- GridLayer gridLayer = new GridLayer(composite, columnHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
-
-
-
- natTable = new NatTable(parent, gridLayer, false);
+ GridLayer gridLayer = new GridLayer(composite, sortHeaderLayer, fixedSummaryRowHeaderLayer, cornerLayer);
+ natTable.setLayer(gridLayer);
/**
* CONFIGURATION
*/
natTable.setConfigRegistry(configRegistry);
-
//add default configuration because autoconfigure is set to false in constructor
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
// override the default sort configuration and change the mouse bindings
// to sort on a single click
//currently removed sorting because of using the TreeConfiguration
-// natTable.addConfiguration(new SingleClickSortConfiguration());
-
+ natTable.addConfiguration(new SingleClickSortConfiguration());
// add the header menu configuration for adding the column header menu
// with hide/show actions
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
- /**
- * Info label
- */
- Label wsLabel = new Label(toolbarComposite, SWT.NONE);
+
wsLabel.setText(workingSet.getLabel());
wsLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ wsLabel.getParent().layout();
-
- /**
- * Expand/Collapse button
- */
- Button collapseAllButton = new Button(toolbarComposite, SWT.PUSH);
- collapseAllButton.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL));
- collapseAllButton.setToolTipText("Collapse all");
- collapseAllButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- natTable.doCommand(new TreeCollapseAllCommand());
- }
- });
- Button expandAllButton = new Button(toolbarComposite, SWT.PUSH);
- expandAllButton.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL));
- expandAllButton.setToolTipText("Expand all");
- expandAllButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- natTable.doCommand(new TreeExpandAllCommand());
- }
- });
-
- /**
- * Table state persistence
- */
- natTableState = new Properties();
- //load persisted state
- File statePropertiesFile = getStatePropertiesFile();
- FileInputStream inputStream;
- try {
- inputStream = new FileInputStream(statePropertiesFile);
- natTableState.load(inputStream);
- } catch (IOException e) {
- MessagingUtils.info("No initial state properties file found for character matrix");
- }
-
- DisplayPersistenceDialogCommandHandler handler =
- new DisplayPersistenceDialogCommandHandler(natTableState, natTable);
- gridLayer.registerCommandHandler(handler);
- // create a combobox for showing the available view states
- ComboViewer comboStates= new ComboViewer(toolbarComposite, SWT.DROP_DOWN) ;
- Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState);
- comboStates.setLabelProvider(new LabelProvider(){
- @Override
- public String getText(Object element) {
- if(element instanceof String && ((String) element).isEmpty()){
- return "-default-";
- }
- return super.getText(element);
- }
- });
- comboStates.setContentProvider(new ArrayContentProvider());
- comboStates.addSelectionChangedListener(e->
- {
- int index = comboStates.getCombo().getSelectionIndex();
- if (index >= 0) {
- String selected = comboStates.getCombo().getItem(index);
- // load the state
- natTable.loadState(selected, natTableState);
- natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected);
- }
- });
- comboStates.setInput(availableStates);
- if(comboStates.getCombo().getItemCount()>0){
- comboStates.getCombo().select(0);
- }
-
- // add listener to update the combo on view state management changes
- handler.addStateChangeListener(new IStateChangedListener() {
- @Override
- public void handleStateChange(StateChangeEvent event) {
- comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState));
- selectStateItem(comboStates, event.getViewConfigName());
- }
- });
-
- // add button to show dialog
- Button btnManageState = new Button(toolbarComposite, SWT.PUSH);
- btnManageState.setImage(ImageResources.getImage(ImageResources.SETTINGS));
- btnManageState.setToolTipText("View configuration");
- btnManageState.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- natTable.doCommand(new DisplayPersistenceDialogCommand(natTable));
- selectStateItem(comboStates, natTableState.get(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY).toString());
- }
- });
-
- /**
- * excel export
- */
- Button btnExcelExport = new Button(toolbarComposite, SWT.PUSH);
- btnExcelExport.setToolTipText("Export to Excel");
- btnExcelExport.setImage(ImageResources.getImage(ImageResources.EXPORT));
- btnExcelExport.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- natTable.doCommand(
- new ExportCommand(
- natTable.getConfigRegistry(),
- natTable.getShell()));
- }
- });
-
- /**
- * bottom button toolbar
- */
- Composite buttonPanel = new Composite(parent, SWT.NONE);
buttonPanel.setLayout(new RowLayout());
GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonPanel);