Project

General

Profile

Download (2.22 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.perspective;
10

    
11
import java.util.List;
12

    
13
import javax.annotation.PostConstruct;
14

    
15
import org.eclipse.e4.ui.model.application.MApplication;
16
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
17
import org.eclipse.e4.ui.workbench.modeling.EModelService;
18
import org.eclipse.e4.ui.workbench.modeling.EPartService;
19
import org.eclipse.nebula.widgets.tablecombo.TableCombo;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.events.SelectionListener;
23
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Display;
26
import org.eclipse.swt.widgets.TableItem;
27

    
28
/**
29
 * @author pplitzner
30
 * @since Nov 16, 2017
31
 *
32
 */
33
public class PerspectiveSwitch {
34

    
35
    @PostConstruct
36
    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);
41

    
42
        List<MPerspective> perspectives = modelService.findElements(application, null, MPerspective.class, null);
43

    
44
        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);
58
            }
59

    
60
            @Override
61
            public void widgetDefaultSelected(SelectionEvent e) {
62
                // TODO Auto-generated method stub
63

    
64
            }
65
        });
66

    
67
    }
68

    
69
}
(4-4/8)