slam4:gui:jface

Ceci est une ancienne révision du document !


JFace

Instanciation

1
2
lvTest = new ListViewer(compoLeft, SWT.BORDER | SWT.V_SCROLL);
List listTest = lvTest.getList();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package net.ex.categorie.main;
 
import java.util.ArrayList;
 
public class MyApp2 {
 
    protected Shell shell;
    private Table tableProduits;
    private java.util.List<Categorie> categories;
    private ListViewer lvCategories;
    private Categorie categorieActive;
    private TableColumnLayout tLayout;
 
    /**
     * Launch the application.
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            MyApp2 window = new MyApp2();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
 
    /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell();
        shell.setSize(523, 406);
        shell.setText("SWT Application");
        shell.setLayout(new FillLayout(SWT.HORIZONTAL));
 
        SashForm sashMain = new SashForm(shell, SWT.NONE);
 
        Composite compoLeft = new Composite(sashMain, SWT.NONE);
        compoLeft.setLayout(new FillLayout(SWT.HORIZONTAL));
 
        lvCategories = new ListViewer(compoLeft, SWT.BORDER | SWT.V_SCROLL);
        List listCategories = lvCategories.getList();
        listCategories.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                StructuredSelection sel = (StructuredSelection) lvCategories.getSelection();
                categorieActive = (Categorie) sel.getFirstElement();
            }
        });
 
        Composite compoRight = new Composite(sashMain, SWT.NONE);
        compoRight.setLayout(new FillLayout(SWT.HORIZONTAL));
 
        SashForm sashForm = new SashForm(compoRight, SWT.VERTICAL);
 
        Composite composite = new Composite(sashForm, SWT.NONE);
        tLayout = new TableColumnLayout();
        composite.setLayout(tLayout);
 
        TableViewer tvProduits = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
        tableProduits = tvProduits.getTable();
        tableProduits.setHeaderVisible(true);
        tableProduits.setLinesVisible(true);
 
        createColumn(tableProduits, "Nom", 10);
        createColumn(tableProduits, "Couleur", 5);
 
        Composite composite_1 = new Composite(sashForm, SWT.NONE);
        sashForm.setWeights(new int[] { 1, 1 });
        sashMain.setWeights(new int[] { 2, 5 });
 
        loadCategories();
    }
 
    private void createColumn(Table table, String caption, int weight) {
        TableColumn col = new TableColumn(table, SWT.NONE);
        col.setText(caption);
        tLayout.setColumnData(col, new ColumnWeightData(10));
    }
 
    public void loadCategories() {
        lvCategories.setContentProvider(new ArrayContentProvider());
        lvCategories.setInput(getCategories());
    }
 
    public java.util.List<Categorie> getCategories() {
        categories = new ArrayList<>();
        categories.add(new Categorie("catégorie 1", new String[] { "elem1", "elem2" }));
        categories.add(new Categorie("catégorie 2", new String[] { "elem3" }));
        categories.add(new Categorie("catégorie 3", new String[] { "elem4" }));
        return categories;
    }
}

  • slam4/gui/jface.1395326999.txt.gz
  • Dernière modification : il y a 6 ans
  • (modification externe)