Revision 66832abf
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java | ||
---|---|---|
36 | 36 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
37 | 37 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
38 | 38 |
import org.eclipse.jface.layout.GridDataFactory; |
39 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
40 |
import org.eclipse.jface.viewers.ComboViewer; |
|
41 |
import org.eclipse.jface.viewers.LabelProvider; |
|
39 | 42 |
import org.eclipse.jface.viewers.StructuredSelection; |
40 | 43 |
import org.eclipse.jface.window.Window; |
41 | 44 |
import org.eclipse.nebula.widgets.nattable.NatTable; |
... | ... | |
95 | 98 |
import org.eclipse.swt.layout.GridData; |
96 | 99 |
import org.eclipse.swt.layout.GridLayout; |
97 | 100 |
import org.eclipse.swt.widgets.Button; |
98 |
import org.eclipse.swt.widgets.Combo; |
|
99 | 101 |
import org.eclipse.swt.widgets.Composite; |
100 | 102 |
|
101 | 103 |
import ca.odell.glazedlists.EventList; |
... | ... | |
478 | 480 |
new DisplayPersistenceDialogCommandHandler(natTableState, natTable); |
479 | 481 |
gridLayer.registerCommandHandler(handler); |
480 | 482 |
// create a combobox for showing the available view states |
481 |
Combo comboStates = new Combo(toolbarComposite, SWT.DROP_DOWN);
|
|
483 |
ComboViewer comboStates= new ComboViewer(toolbarComposite, SWT.DROP_DOWN) ;
|
|
482 | 484 |
Collection<String> availableStates = PersistenceHelper.getAvailableStates(natTableState); |
483 |
comboStates.setItems(availableStates.toArray(new String[] {})); |
|
484 |
|
|
485 |
comboStates.addSelectionListener(new SelectionAdapter() { |
|
485 |
comboStates.setLabelProvider(new LabelProvider(){ |
|
486 | 486 |
@Override |
487 |
public void widgetSelected(SelectionEvent e) { |
|
488 |
int index = comboStates.getSelectionIndex(); |
|
489 |
if (index >= 0) { |
|
490 |
String selected = comboStates.getItem(index); |
|
491 |
// load the state |
|
492 |
natTable.loadState(selected, natTableState); |
|
493 |
natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected); |
|
487 |
public String getText(Object element) { |
|
488 |
if(element instanceof String && ((String) element).isEmpty()){ |
|
489 |
return "-default-"; |
|
494 | 490 |
} |
491 |
return super.getText(element); |
|
495 | 492 |
} |
496 | 493 |
}); |
494 |
comboStates.setContentProvider(new ArrayContentProvider()); |
|
495 |
comboStates.addSelectionChangedListener(e-> |
|
496 |
{ |
|
497 |
int index = comboStates.getCombo().getSelectionIndex(); |
|
498 |
if (index >= 0) { |
|
499 |
String selected = comboStates.getCombo().getItem(index); |
|
500 |
// load the state |
|
501 |
natTable.loadState(selected, natTableState); |
|
502 |
natTableState.setProperty(PersistenceDialog.ACTIVE_VIEW_CONFIGURATION_KEY, selected); |
|
503 |
} |
|
504 |
}); |
|
505 |
comboStates.setInput(availableStates); |
|
506 |
if(comboStates.getCombo().getItemCount()>0){ |
|
507 |
comboStates.getCombo().select(0); |
|
508 |
} |
|
497 | 509 |
|
498 | 510 |
// add listener to update the combo on view state management changes |
499 | 511 |
handler.addStateChangeListener(new IStateChangedListener() { |
500 | 512 |
@Override |
501 | 513 |
public void handleStateChange(StateChangeEvent event) { |
502 |
comboStates.setItems(PersistenceHelper.getAvailableStates(natTableState) |
|
503 |
.toArray(new String[] {})); |
|
514 |
comboStates.setInput(PersistenceHelper.getAvailableStates(natTableState)); |
|
504 | 515 |
selectStateItem(comboStates, event.getViewConfigName()); |
505 | 516 |
} |
506 | 517 |
}); |
... | ... | |
561 | 572 |
parent.layout(); |
562 | 573 |
} |
563 | 574 |
|
564 |
private void selectStateItem(Combo comboStates, String stateName){ |
|
565 |
String[] items = comboStates.getItems(); |
|
575 |
private void selectStateItem(ComboViewer comboStates, String stateName){
|
|
576 |
String[] items = comboStates.getCombo().getItems();
|
|
566 | 577 |
for(int i=0;i<items.length;i++){ |
567 | 578 |
if(items[i].equals(stateName)){ |
568 |
comboStates.select(i); |
|
579 |
comboStates.getCombo().select(i);
|
|
569 | 580 |
break; |
570 | 581 |
} |
571 | 582 |
} |
Also available in: Unified diff
ref #7095 add label for default viewConfiguration