01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.dialogs;
06:
07: import org.eclipse.jface.dialogs.IDialogConstants;
08: import org.eclipse.jface.dialogs.MessageDialog;
09: import org.eclipse.swt.SWT;
10: import org.eclipse.swt.events.SelectionAdapter;
11: import org.eclipse.swt.events.SelectionEvent;
12: import org.eclipse.swt.layout.GridData;
13: import org.eclipse.swt.layout.GridLayout;
14: import org.eclipse.swt.widgets.Button;
15: import org.eclipse.swt.widgets.Composite;
16: import org.eclipse.swt.widgets.Control;
17: import org.eclipse.swt.widgets.DirectoryDialog;
18: import org.eclipse.swt.widgets.Shell;
19: import org.eclipse.swt.widgets.Text;
20: import org.terracotta.ui.util.SWTUtil;
21:
22: import java.io.File;
23: import java.net.MalformedURLException;
24:
25: public class RepoLocationDialog extends MessageDialog {
26:
27: private Text m_repoLocation;
28: private Button m_browseButton;
29: private ValueListener m_valueListener;
30:
31: public RepoLocationDialog(Shell parentShell, String title,
32: String message) {
33: super (parentShell, title, null, message, MessageDialog.NONE,
34: new String[] { IDialogConstants.OK_LABEL,
35: IDialogConstants.CANCEL_LABEL }, 0);
36: }
37:
38: protected Control createCustomArea(Composite parent) {
39: Composite comp = new Composite(parent, SWT.NONE);
40: comp.setLayout(new GridLayout(2, false));
41: comp.setLayoutData(new GridData(GridData.FILL_BOTH));
42:
43: m_repoLocation = new Text(comp, SWT.SINGLE | SWT.BORDER);
44: m_repoLocation.setLayoutData(new GridData(
45: GridData.FILL_HORIZONTAL));
46:
47: m_browseButton = new Button(comp, SWT.PUSH);
48: m_browseButton.setText("Browse...");
49: m_browseButton.addSelectionListener(new SelectionAdapter() {
50: public void widgetSelected(SelectionEvent e) {
51: DirectoryDialog directoryDialog = new DirectoryDialog(
52: getShell());
53: directoryDialog
54: .setText("Terracotta Module Repository Chooser");
55: directoryDialog
56: .setMessage("Select a module repository directory");
57: String path = directoryDialog.open();
58: if (path != null) {
59: File dir = new File(path);
60: try {
61: m_repoLocation.setText(dir.toURL().toString());
62: } catch (MalformedURLException mure) {/**/
63: }
64: }
65: }
66: });
67: SWTUtil.applyDefaultButtonSize(m_browseButton);
68:
69: return m_repoLocation;
70: }
71:
72: protected void buttonPressed(int buttonId) {
73: if (buttonId == IDialogConstants.OK_ID) {
74: if (m_valueListener != null)
75: m_valueListener.setValues(m_repoLocation.getText());
76: }
77: super .buttonPressed(buttonId);
78: }
79:
80: public void addValueListener(ValueListener listener) {
81: this .m_valueListener = listener;
82: }
83:
84: // --------------------------------------------------------------------------------
85:
86: public static interface ValueListener {
87: void setValues(String repoLocation);
88: }
89: }
|