11package de .hetzge .eclipse .aicoder ;
22
3- import java .time .Duration ;
43import java .util .List ;
54import java .util .UUID ;
65
1514import org .eclipse .swt .widgets .Shell ;
1615import org .eclipse .swt .widgets .Text ;
1716
18- import de .hetzge .eclipse .aicoder .context .ContextContext ;
1917import de .hetzge .eclipse .aicoder .context .CustomContextEntry ;
18+ import de .hetzge .eclipse .aicoder .context .CustomContextEntryData ;
2019
2120public class CustomContextEntryDialog extends Dialog {
2221
23- private Text titleText ;
24- private Text contentText ;
25- private Text globText ;
26-
27- private String title ;
28- private String content ;
29- private String glob ;
30-
31- private final CustomContextEntry existingEntry ;
32-
33- public CustomContextEntryDialog (Shell parentShell , CustomContextEntry existingEntry ) {
34- super (parentShell );
35- this .existingEntry = existingEntry ;
36- if (existingEntry != null ) {
37- this .title = existingEntry .getTitle ();
38- this .content = existingEntry .getContent (new ContextContext ());
39- this .glob = existingEntry .getGlob ();
40- }
41- }
42-
43- @ Override
44- protected Control createDialogArea (Composite parent ) {
45- final Composite container = (Composite ) super .createDialogArea (parent );
46- final GridLayout layout = new GridLayout (2 , false );
47- container .setLayout (layout );
48-
49- // Title
50- final Label titleLabel = new Label (container , SWT .NONE );
51- titleLabel .setText ("Title:" );
52-
53- this .titleText = new Text (container , SWT .BORDER );
54- this .titleText .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
55- if (this .title != null ) {
56- this .titleText .setText (this .title );
57- }
58-
59- // Glob pattern
60- final Label globLabel = new Label (container , SWT .NONE );
61- globLabel .setText ("Glob Pattern:" );
62-
63- this .globText = new Text (container , SWT .BORDER );
64- this .globText .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
65- if (this .glob != null ) {
66- this .globText .setText (this .glob );
67- }
68-
69- // Content
70- final Label contentLabel = new Label (container , SWT .NONE );
71- contentLabel .setText ("Content:" );
72- contentLabel .setLayoutData (new GridData (SWT .LEFT , SWT .TOP , false , false ));
73-
74- this .contentText = new Text (container , SWT .BORDER | SWT .MULTI | SWT .WRAP | SWT .V_SCROLL );
75- final GridData contentData = new GridData (GridData .FILL_BOTH );
76- contentData .heightHint = 200 ; // Reasonable default height
77- this .contentText .setLayoutData (contentData );
78- if (this .content != null ) {
79- this .contentText .setText (this .content );
80- }
81-
82- return container ;
83- }
84-
85- @ Override
86- protected void configureShell (Shell shell ) {
87- super .configureShell (shell );
88- shell .setText (this .existingEntry != null ? "Edit Custom Context Entry" : "New Custom Context Entry" );
89- shell .setMinimumSize (600 , 400 ); // Set a wider minimum size
90- }
91-
92- @ Override
93- protected void createButtonsForButtonBar (Composite parent ) {
94- createButton (parent , IDialogConstants .OK_ID , "Save" , true );
95- createButton (parent , IDialogConstants .CANCEL_ID , "Cancel" , false );
96- }
97-
98- @ Override
99- protected void okPressed () {
100- // Save the values
101- this .title = this .titleText .getText ().trim ();
102- this .content = this .contentText .getText ();
103- this .glob = this .globText .getText ().trim ();
104-
105- super .okPressed ();
106- }
107-
108- public CustomContextEntry createEntry () {
109- final UUID id = this .existingEntry != null ? this .existingEntry .getId () : UUID .randomUUID ();
110- return new CustomContextEntry (
111- this .existingEntry != null ? this .existingEntry .getChildContextEntries () : List .of (),
112- id ,
113- this .title ,
114- this .content ,
115- this .glob ,
116- Duration .ZERO
117- );
118- }
22+ private Text titleText ;
23+ private Text contentText ;
24+ private Text globText ;
25+
26+ private String title ;
27+ private String content ;
28+ private String glob ;
29+
30+ private final CustomContextEntry existingEntry ;
31+
32+ public CustomContextEntryDialog (Shell parentShell , CustomContextEntry existingEntry ) {
33+ super (parentShell );
34+ this .existingEntry = existingEntry ;
35+ if (existingEntry != null ) {
36+ final CustomContextEntryData data = existingEntry .getData ();
37+ this .title = data .getTitle ();
38+ this .content = data .getContent ();
39+ this .glob = data .getGlob ();
40+ }
41+ }
42+
43+ @ Override
44+ protected Control createDialogArea (Composite parent ) {
45+ final Composite container = (Composite ) super .createDialogArea (parent );
46+ final GridLayout layout = new GridLayout (2 , false );
47+ container .setLayout (layout );
48+
49+ // Title
50+ final Label titleLabel = new Label (container , SWT .NONE );
51+ titleLabel .setText ("Title:" );
52+
53+ this .titleText = new Text (container , SWT .BORDER );
54+ this .titleText .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
55+ if (this .title != null ) {
56+ this .titleText .setText (this .title );
57+ }
58+
59+ // Glob pattern
60+ final Label globLabel = new Label (container , SWT .NONE );
61+ globLabel .setText ("Glob Pattern:" );
62+
63+ this .globText = new Text (container , SWT .BORDER );
64+ this .globText .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
65+ if (this .glob != null ) {
66+ this .globText .setText (this .glob );
67+ }
68+
69+ // Content
70+ final Label contentLabel = new Label (container , SWT .NONE );
71+ contentLabel .setText ("Content:" );
72+ contentLabel .setLayoutData (new GridData (SWT .LEFT , SWT .TOP , false , false ));
73+
74+ this .contentText = new Text (container , SWT .BORDER | SWT .MULTI | SWT .WRAP | SWT .V_SCROLL );
75+ final GridData contentData = new GridData (GridData .FILL_BOTH );
76+ contentData .heightHint = 200 ; // Reasonable default height
77+ this .contentText .setLayoutData (contentData );
78+ if (this .content != null ) {
79+ this .contentText .setText (this .content );
80+ }
81+
82+ return container ;
83+ }
84+
85+ @ Override
86+ protected void configureShell (Shell shell ) {
87+ super .configureShell (shell );
88+ shell .setText (this .existingEntry != null ? "Edit Custom Context Entry" : "New Custom Context Entry" );
89+ shell .setMinimumSize (600 , 400 ); // Set a wider minimum size
90+ }
91+
92+ @ Override
93+ protected void createButtonsForButtonBar (Composite parent ) {
94+ createButton (parent , IDialogConstants .OK_ID , "Save" , true );
95+ createButton (parent , IDialogConstants .CANCEL_ID , "Cancel" , false );
96+ }
97+
98+ @ Override
99+ protected void okPressed () {
100+ // Save the values
101+ this .title = this .titleText .getText ().trim ();
102+ this .content = this .contentText .getText ();
103+ this .glob = this .globText .getText ().trim ();
104+
105+ super .okPressed ();
106+ }
107+
108+ public CustomContextEntryData createEntry () {
109+ final UUID id = this .existingEntry != null ? this .existingEntry .getData ().getId () : UUID .randomUUID ();
110+ return new CustomContextEntryData (
111+ id ,
112+ this .existingEntry != null ? this .existingEntry .getData ().getChildren () : List .of (),
113+ this .title ,
114+ this .content ,
115+ this .glob );
116+ }
119117}
0 commit comments