View Javadoc
1   package org.argeo.tracker.ui.dialogs;
2   
3   import javax.jcr.Node;
4   
5   import org.argeo.connect.util.ConnectJcrUtils;
6   import org.argeo.eclipse.ui.EclipseUiUtils;
7   import org.eclipse.jface.dialogs.TrayDialog;
8   import org.eclipse.swt.SWT;
9   import org.eclipse.swt.graphics.Point;
10  import org.eclipse.swt.layout.GridLayout;
11  import org.eclipse.swt.widgets.Composite;
12  import org.eclipse.swt.widgets.Control;
13  import org.eclipse.swt.widgets.Label;
14  import org.eclipse.swt.widgets.Shell;
15  import org.eclipse.swt.widgets.Text;
16  
17  /** Edit a free text value */
18  public class EditFreeTextDialog extends TrayDialog {
19  	private static final long serialVersionUID = -2526572299370624808L;
20  
21  	// Business objects
22  	private final Node node;
23  	private final String propName;
24  	private String updatedText;
25  
26  	// UI objects
27  	private Text text;
28  	private final String title;
29  
30  	public EditFreeTextDialog(Shell parentShell, String title, Node node,
31  			String propName) {
32  		super(parentShell);
33  		this.title = title;
34  		this.node = node;
35  		this.propName = propName;
36  	}
37  
38  	protected Point getInitialSize() {
39  		return new Point(400, 400);
40  	}
41  
42  	@Override
43  	protected void okPressed() {
44  		updatedText = text.getText();
45  		super.okPressed();
46  	}
47  
48  	protected Control createDialogArea(Composite parent) {
49  		Composite dialogArea = (Composite) super.createDialogArea(parent);
50  		dialogArea.setLayout(new GridLayout());
51  		new Label(dialogArea, SWT.WRAP).setText("Please modify the below text");
52  		text = new Text(dialogArea, SWT.WRAP | SWT.MULTI | SWT.BORDER);
53  		text.setLayoutData(EclipseUiUtils.fillAll());
54  		text.setText(ConnectJcrUtils.get(node, propName));
55  		parent.pack();
56  		return dialogArea;
57  	}
58  
59  	public String getEditedText() {
60  		return updatedText;
61  	}
62  
63  	protected void configureShell(Shell shell) {
64  		super.configureShell(shell);
65  		shell.setText(title);
66  	}
67  }