import java.io.IOException;
import java.util.Collection;
import java.util.Properties;
+import java.util.function.Consumer;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
private void init() {
setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- setLayout(new GridLayout(9, false));
+ setLayout(new GridLayout(10, false));
wsLabel = new Label(this, SWT.NONE);
- Button btnToggleToolTips = new Button(this, SWT.TOGGLE);
+ Button btnToggleTooltips = new Button(this, SWT.TOGGLE);
Button btnToggleTree = new Button(this, SWT.PUSH);
Button btnToggleFlat = new Button(this, SWT.PUSH);
Button btnCollapseAll = new Button(this, SWT.PUSH);
Button btnExcelExport = new Button(this, SWT.PUSH);
/**
- * Toogle tooltips button
+ * Toggle tooltips button
*/
- btnToggleToolTips.setImage(ImageResources.getImage(ImageResources.LIGHT_BULB));
- btnToggleToolTips.setToolTipText("Show tooltips");
- btnToggleToolTips.setSelection(true);
- btnToggleToolTips.setEnabled(true);
- btnToggleToolTips.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- matrix.toogleIsShowTooltips();
- }
- });
-
+ initButton(
+ btnToggleTooltips,
+ ImageResources.getImage(ImageResources.LIGHT_BULB),
+ "Show tooltips",
+ null,
+ true,
+ true,
+ (e)->matrix.toogleIsShowTooltips()
+ );
/**
* Toogle tree button
*/
- btnToggleTree.setImage(ImageResources.getImage(ImageResources.HIERARCHICAL));
- btnToggleTree.setToolTipText(Messages.CharacterMatrix_SHOW_HIERARCHY);
- btnToggleTree.setSelection(true);
- btnToggleTree.setEnabled(false);
- btnToggleTree.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- matrix.toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
- }
- });
+ initButton(
+ btnToggleTree,
+ ImageResources.getImage(ImageResources.HIERARCHICAL),
+ Messages.CharacterMatrix_SHOW_HIERARCHY,
+ null,
+ false,
+ true,
+ (e)->matrix.toggleTreeFlat(true, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo)
+ );
/**
* Toogle flat button
*/
- btnToggleFlat.setImage(ImageResources.getImage(ImageResources.FLAT));
- btnToggleFlat.setToolTipText(Messages.CharacterMatrix_SHOW_FLAT_LIST);
- btnToggleFlat.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- matrix.toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo);
- }
- });
+ initButton(
+ btnToggleFlat,
+ ImageResources.getImage(ImageResources.FLAT),
+ Messages.CharacterMatrix_SHOW_FLAT_LIST,
+ null,
+ true,
+ false,
+ (e)->matrix.toggleTreeFlat(false, btnToggleFlat, btnToggleTree, btnCollapseAll, btnExpandAll, btnFreezeSuppInfo)
+ );
/**
*
* Collapse button
*/
- btnCollapseAll.setImage(ImageResources.getImage(ImageResources.COLLAPSE_ALL));
- btnCollapseAll.setToolTipText(Messages.CharacterMatrix_COLLAPSE);
- btnCollapseAll.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- matrix.getNatTable().doCommand(new TreeCollapseAllCommand());
- }
- });
+ initButton(
+ btnCollapseAll,
+ ImageResources.getImage(ImageResources.COLLAPSE_ALL),
+ Messages.CharacterMatrix_COLLAPSE,
+ null,
+ true,
+ false,
+ (e)->matrix.getNatTable().doCommand(new TreeCollapseAllCommand())
+ );
/**
* Expand button
*/
- btnExpandAll.setImage(ImageResources.getImage(ImageResources.EXPAND_ALL));
- btnExpandAll.setToolTipText(Messages.CharacterMatrix_EXPAND);
- btnExpandAll.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- matrix.getNatTable().doCommand(new TreeExpandAllCommand());
- }
- });
+ initButton(
+ btnExpandAll,
+ ImageResources.getImage(ImageResources.EXPAND_ALL),
+ Messages.CharacterMatrix_EXPAND,
+ null,
+ true,
+ false,
+ (e)->matrix.getNatTable().doCommand(new TreeExpandAllCommand())
+ );
/**
* Freeze supplemental info button
*/
- btnFreezeSuppInfo.setImage(ImageResources.getImage(ImageResources.LOCK_ICON));
- btnFreezeSuppInfo.setToolTipText(Messages.CharacterMatrix_LOCK_COLUMNS);
- btnFreezeSuppInfo.setSelection(true);
- btnFreezeSuppInfo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- boolean isSelected = btnFreezeSuppInfo.getSelection();
- matrix.freezeSupplementalColumns(isSelected);
- btnFreezeSuppInfo.setImage(isSelected?
- ImageResources.getImage(ImageResources.LOCK_ICON):
- ImageResources.getImage(ImageResources.LOCK_OPEN_ICON));
- }
- });
+ initButton(
+ btnFreezeSuppInfo,
+ ImageResources.getImage(ImageResources.LOCK_ICON),
+ Messages.CharacterMatrix_LOCK_COLUMNS,
+ null,
+ true,
+ true,
+ (e)->{
+ boolean isSelected = btnFreezeSuppInfo.getSelection();
+ matrix.freezeSupplementalColumns(isSelected);
+ btnFreezeSuppInfo.setImage(isSelected?
+ ImageResources.getImage(ImageResources.LOCK_ICON):
+ ImageResources.getImage(ImageResources.LOCK_OPEN_ICON));
+ }
+ );
/**
* Table state persistence
}
+ private void initButton(Button button, Image image, String tooltipText,
+ String label, boolean enabled, boolean selected, Consumer<SelectionEvent> widgetSelected){
+ if(image!=null){
+ button.setImage(image);
+ }
+ if(label!=null){
+ button.setText(label);
+ }
+ if(tooltipText!=null){
+ button.setToolTipText(tooltipText);
+ }
+ button.setSelection(selected);
+ button.setEnabled(enabled);
+ button.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ widgetSelected.accept(e);
+ }
+ });
+ }
+
public Label getWsLabel() {
return wsLabel;
}