Bonjour,
Je suis en train de suivre un livre pour apprendre le développement d'application RAP et je rencontre un problème d'affichage d'un formulaire, celui-ci ne s'affiche tout simplement pas...
J'ai une classe "CatEditor" qui est appelée lorsque je double-clique sur une ligne d'une table qui elle s'affiche bien (depuis la classe qui représente ma vue "CatShelterView").
La classe "CatEditor" construit un simple formulaire et normalement devrait l'afficher à l'écran mais ce n'est pas le cas.
En debug je passe bien dans la méthode qui construit le formulaire mais c'est comme si je pointais sur le mauvais parent (je ne maitrise pas encore très bien, et de loin, la notion de parent, composite, shell ....)
Voici les 2 classes en question :
CatShelteView
Et la classe CatEditor
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class CatShelterView extends ViewPart { public static final String ID = "catshelter.view"; private TableViewer viewer; public CatShelterView() { } public TableViewer getViewer() { return viewer; } @Override public void createPartControl(Composite parent) { parent.setLayout(new FillLayout(SWT.VERTICAL)); Label helloWorld = new Label(parent, SWT.HORIZONTAL); helloWorld.setText("Those cats need new can opener"); viewer = new TableViewer(parent); CatLabelProvider labels = new CatLabelProvider(); labels.createColumns(viewer); viewer.setLabelProvider(labels); viewer.setContentProvider(new CatsProvider()); viewer.setInput(getSite()); getSite().setSelectionProvider(viewer); addEditor(viewer); } private void addEditor(StructuredViewer viewer) { viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { ISelection selection = getViewer().getSelection(); if (selection instanceof IStructuredSelection) { List selectionList = ((IStructuredSelection) selection).toList(); for (Object selectedObject : selectionList) { if (selectedObject instanceof Cat) { CatEditorInput input = new CatEditorInput((Cat) selectedObject); try { getSite().getPage().openEditor(input, CatEditor.ID); } catch (PartInitException e) { throw new RuntimeException(CatEditor.ID + " not found"); } } } } } }); } @Override public void setFocus() { } }
Et si jamais en fichier zip mon projet qui contient toutes les classes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
110
111
112
113
114
115
116
117
118
119 public class CatEditor extends EditorPart { public static final String ID = "catshelter.editor"; private Cat cat; private static final GridData FILL = new GridData(GridData.FILL_HORIZONTAL); private Button male; private Button female; private Text name; private Text likes; private Button save; public CatEditor() { super(); } @Override public void doSave(IProgressMonitor monitor) { } @Override public void doSaveAs() { } @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (!(input instanceof CatEditorInput)) { throw new RuntimeException("Input not of type " + CatEditorInput.class.getName()); } setSite(site); setInput(input); setPartName(input.getName()); cat = (Cat) input.getAdapter(Cat.class); } @Override public boolean isDirty() { return false; } @Override public boolean isSaveAsAllowed() { return false; } @Override public void createPartControl(Composite parent) { FormToolkit tk = new FormToolkit(parent.getDisplay()); Composite body = tk.createForm(parent).getBody(); body.setLayoutData(new GridLayout(2, true)); tk.createLabel(body, "Name:"); name = new Text(body, SWT.BORDER); name.setLayoutData(FILL); tk.createLabel(body, "Likes:"); likes = new Text(body, SWT.BORDER); likes.setLayoutData(FILL); tk.createLabel(body, "Gender:"); Composite group = tk.createComposite(body); group.setLayout(new FillLayout(SWT.VERTICAL)); male = tk.createButton(group, "Male", SWT.RADIO); female = tk.createButton(group, "Female", SWT.RADIO); setValuesToFields(cat); save = tk.createButton(group, "Save", SWT.PUSH); save.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { saveValuesToModel(cat); IWorkbenchPage page = getSite().getPage(); IViewPart view = page.findView(CatShelterView.ID); if (view instanceof CatShelterView) { ((CatShelterView) view).getViewer().refresh(); } } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); } private void setValuesToFields(Cat cat) { name.setText(cat.getName()); likes.setText(cat.getLikes()); switch(cat.getGender()) { case male : this.male.setSelection(true); break; case female : this.female.setSelection(true); break; } } private void saveValuesToModel(Cat cat) { cat.setName(name.getText()); cat.setLikes(likes.getText()); if (male.getSelection()) { cat.setGender(Gender.male); } else if (female.getSelection()) { cat.setGender(Gender.female); } } @Override public void setFocus() { } }
catshelter.zip
D'avance un grand merci pour votre aide
Partager