Bonjour à tous.
Mon problème est le suivant :
Je récupère un code XML (tout en ligne) que j'affiche dans un Text.
Ce XML (qui peut être parfois assez long en longueur vu qu'il est sur une même ligne) dépasse très souvent de mon Text.
Je cherche donc à formater ce XML dans ce Text comme on peut le faire sur Eclipse en faisant Ctrl+Shift+F, soit en créant un raccourci qui fera ce formatage soit en codant une méthode qui affichera le XML déjà formaté.
Voici mon code :
En espérant avoir été clair dans mes explications.
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 import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class AffichageFormateDialog extends Dialog{ private Shell dialog; private String texte; private String type; private int height = 750; private int width = 650; public AffichageFormateDialog(Shell parent) { super(parent); } public AffichageFormateDialog(Shell parent, String texte, String type){ this(parent); this.texte = texte; this.type = type; } public String open() { Shell parent = getParent(); /*Shell*/ dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.setSize(width, height); dialog.setText("Affichage du " + this.type); Rectangle parentSize = getParent().getBounds(); int locationX, locationY; locationX = (parentSize.width - width)/2+parentSize.x; locationY = (parentSize.height - height)/2+parentSize.y; dialog.setLocation(new Point(locationX, locationY)); createContent(); dialog.open(); Display display = parent.getDisplay(); while (!dialog.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } return "OK"; } private void createContent(){ GridLayout layoutComposite = new GridLayout(); layoutComposite.marginHeight=0; layoutComposite.marginWidth=0; dialog.setLayout(layoutComposite); Composite cAffichage = new Composite(dialog, SWT.BORDER); GridLayout glcAffichage = new GridLayout(1, false); cAffichage.setLayout(glcAffichage); GridData gdcAffichage = new GridData(); gdcAffichage.widthHint = 650; gdcAffichage.heightHint = 750; cAffichage.setLayoutData(gdcAffichage); Text txt = new Text(cAffichage, SWT.NONE | SWT.MULTI | SWT.V_SCROLL); txt.setText(this.texte); //txt.setEditable(false); GridData gdTxt = new GridData(); gdTxt.heightHint = 700; gdTxt.widthHint = 620; txt.setLayoutData(gdTxt); } }
Je vous remercie par avance pour votre aide.
Partager