Revision efb6bb74
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/perspective/PerspectiveSwitch.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.perspective; |
10 | 10 |
|
11 |
import java.io.IOException; |
|
12 |
import java.net.URL; |
|
11 | 13 |
import java.util.List; |
12 | 14 |
|
13 | 15 |
import javax.annotation.PostConstruct; |
14 | 16 |
|
17 |
import org.eclipse.core.runtime.FileLocator; |
|
15 | 18 |
import org.eclipse.e4.ui.model.application.MApplication; |
16 | 19 |
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; |
17 | 20 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
18 | 21 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
19 |
import org.eclipse.nebula.widgets.tablecombo.TableCombo;
|
|
22 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
20 | 23 |
import org.eclipse.swt.SWT; |
21 | 24 |
import org.eclipse.swt.events.SelectionEvent; |
22 | 25 |
import org.eclipse.swt.events.SelectionListener; |
23 |
import org.eclipse.swt.graphics.Image; |
|
24 | 26 |
import org.eclipse.swt.widgets.Composite; |
25 |
import org.eclipse.swt.widgets.Display; |
|
26 |
import org.eclipse.swt.widgets.TableItem; |
|
27 |
import org.eclipse.swt.widgets.ToolBar; |
|
28 |
import org.eclipse.swt.widgets.ToolItem; |
|
29 |
|
|
27 | 30 |
|
28 | 31 |
/** |
29 | 32 |
* @author pplitzner |
... | ... | |
34 | 37 |
|
35 | 38 |
@PostConstruct |
36 | 39 |
public void create(Composite parent, MApplication application, EModelService modelService, |
37 |
EPartService partService){ |
|
38 |
TableCombo combo = new TableCombo(parent, SWT.BORDER | SWT.READ_ONLY | SWT.SINGLE); |
|
39 |
|
|
40 |
Image image = Display.getDefault().getSystemImage(SWT.ICON_ERROR); |
|
40 |
EPartService partService) throws IOException { |
|
41 |
ToolBar toolbar = new ToolBar(parent, SWT.WRAP); |
|
41 | 42 |
|
42 | 43 |
List<MPerspective> perspectives = modelService.findElements(application, null, MPerspective.class, null); |
43 | 44 |
|
44 | 45 |
for (MPerspective perspective : perspectives) { |
45 |
TableItem ti = new TableItem(combo.getTable(), SWT.NONE);
|
|
46 |
ti.setText(perspective.getLabel());
|
|
47 |
ti.setData(perspective);
|
|
48 |
// ti.setImage(image);
|
|
49 |
}
|
|
50 |
|
|
51 |
combo.addSelectionListener(new SelectionListener() {
|
|
52 |
|
|
53 |
@Override
|
|
54 |
public void widgetSelected(SelectionEvent e) {
|
|
55 |
TableItem item = combo.getTable().getSelection()[0];
|
|
56 |
MPerspective perspective = (MPerspective) item.getData();
|
|
57 |
partService.switchPerspective(perspective);
|
|
46 |
ToolItem item = new ToolItem(toolbar, SWT.NONE);
|
|
47 |
item.setData(perspective);
|
|
48 |
item.setToolTipText(perspective.getLabel());
|
|
49 |
String iconURI = perspective.getIconURI();
|
|
50 |
if(iconURI!=null){
|
|
51 |
URL url = FileLocator.find(new URL(iconURI)); |
|
52 |
URL fileUrl = FileLocator.toFileURL(url);
|
|
53 |
if(fileUrl!=null){ |
|
54 |
item.setImage(ImageDescriptor.createFromURL(fileUrl).createImage());
|
|
55 |
}
|
|
56 |
}
|
|
57 |
if(item.getImage()==null){
|
|
58 |
item.setText(perspective.getLabel());
|
|
58 | 59 |
} |
59 | 60 |
|
60 |
@Override |
|
61 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
62 |
// TODO Auto-generated method stub |
|
61 |
item.addSelectionListener(new SelectionListener() { |
|
62 |
@Override |
|
63 |
public void widgetSelected(SelectionEvent e) { |
|
64 |
MPerspective perspective = (MPerspective) item.getData(); |
|
65 |
partService.switchPerspective(perspective); |
|
66 |
} |
|
63 | 67 |
|
64 |
} |
|
65 |
}); |
|
68 |
@Override |
|
69 |
public void widgetDefaultSelected(SelectionEvent e) { |
|
70 |
} |
|
71 |
}); |
|
72 |
} |
|
66 | 73 |
|
67 | 74 |
} |
68 | 75 |
|
Also available in: Unified diff
ref #6568 Enhance perspective switcher