001: package tide.exttools.SVN;
002:
003: import java.awt.Insets;
004: import java.awt.FlowLayout;
005: import tide.project.*;
006: import tide.editor.*;
007: import javax.swing.*;
008: import java.awt.BorderLayout;
009: import java.awt.event.*;
010: import javax.swing.border.*;
011: import java.util.*;
012: import java.io.*;
013: import snow.utils.*;
014: import snow.utils.storage.*;
015: import snow.utils.gui.*;
016:
017: /** todo: manage an exclusive access (lock)
018: */
019: public final class SVNSettingsDialog extends JDialog {
020: private final FileField svnRootPath = new FileField("", false,
021: "Give the subversion root path",
022: JFileChooser.DIRECTORIES_ONLY);
023: private final JTextField repositoryPath = new JTextField("", 40);
024: private final JTextField username = new JTextField("", 10);
025: private final JPasswordField password = new JPasswordField("", 10);
026:
027: public static String defaultSVNLocation = "c:/program files/Subversion";
028: public static String homepage = "http://subversion.tigris.org/";
029:
030: public boolean dialogWasAccepted = false;
031:
032: public SVNSettingsDialog(final JFrame parent,
033: final ProjectSettings settings) {
034: super (parent, "Subversion (SVN) settings", true);
035:
036: JComponent tae = GUIUtils
037: .createReadOnlyDescriptionArea("Subversion (SVN) is an external tool for doing version control ("
038: + homepage
039: + ")."
040: + "\r\nIt manages/shares/stores source files, with versions, to work with other persons over the net"
041: + "\non the same project at the same time."
042: + "\n\nREMARK: tIDE SVN support is currently minimal. Only english SVN is supported."
043: + "\n If necessary, rename the folder share/locale in share/locale__."
044: + "\nREMARK: You must have checked out the working directory and it must point on the project sources home."
045: + "\n\nUSAGE: check in/out files from the sources tree popup menu. Hold CTRL for quick access.");
046: add(tae, BorderLayout.NORTH);
047:
048: JPanel inputPanel = new JPanel();
049: add(inputPanel, BorderLayout.CENTER);
050: GridLayout3 gl3 = new GridLayout3(2, inputPanel);
051:
052: gl3.addSeparator();
053: gl3.add("SVN location");
054: gl3.add(svnRootPath);
055: svnRootPath.setPath(settings.getProperty("Subversion_path",
056: defaultSVNLocation));
057: svnRootPath.offerRememberedGlobalCompletion(
058: MainEditorFrame.instance.globalProperties, "knownSVNs");
059: svnRootPath.setComponentWidth(300);
060: svnRootPath.setAutoColorized();
061:
062: gl3.add("Repository URL");
063: JPanel rp = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
064: gl3.add(rp);
065: rp.add(repositoryPath);
066: repositoryPath.setText(settings.getProperty(
067: "Subversion_repositoryPath", ""));
068: // Todo: test button.
069: JButton test = new JButton("test");
070: test.setFocusPainted(false);
071: test.setMargin(new Insets(0, 2, 0, 2));
072: rp.add(test);
073: test.addActionListener(new ActionListener() {
074: public void actionPerformed(ActionEvent ae) {
075: try {
076: test();
077: } catch (Exception e) {
078: JOptionPane.showMessageDialog(null, "Test failed: "
079: + e.getMessage(), "SVN test failed",
080: JOptionPane.ERROR_MESSAGE);
081: }
082:
083: }
084: });
085:
086: gl3.add("Username");
087: gl3.add(username);
088: username.setText(settings
089: .getProperty("Subversion_username", ""));
090:
091: gl3.add("password");
092: gl3.add(password);
093: password.setText(settings
094: .getProperty("Subversion_password", ""));
095:
096: CloseControlPanel ccp = new CloseControlPanel(this , true, true,
097: "Ok");
098: add(ccp, BorderLayout.SOUTH);
099:
100: pack();
101: this .setLocationRelativeTo(parent);
102: this .setVisible(true); // MODAL => waits
103:
104: if (ccp.getWasCancelled())
105: return;
106:
107: dialogWasAccepted = true;
108:
109: // save settings
110: settings.setProperty("Subversion_path", svnRootPath
111: .getTextField().getText());
112: settings.setProperty("Subversion_repositoryPath",
113: repositoryPath.getText());
114: settings.setProperty("Subversion_username", username.getText());
115: settings.setProperty("Subversion_password", new String(password
116: .getPassword()));
117:
118: svnRootPath.rememberPathForGlobalCompletion(
119: MainEditorFrame.instance.globalProperties, "knownSVNs");
120:
121: }
122:
123: // Todo: test password...
124: void test() throws Exception {
125: List<String> args = new ArrayList<String>();
126: args.add(""
127: + svnRootPath.getPath()
128: + (SysUtils.is_Windows_OS() ? "/bin/svn.exe"
129: : "/bin/svn"));
130: args.add("info"); // list ?
131: args.add(this .repositoryPath.getText());
132: //args.add("--verbose"); // show a lot of infos
133:
134: //ProcessBuilder pb = new ProcessBuilder(args);
135: //Process proc = pb.start();
136: String rep = ProcessUtils
137: .readWholeProcessStack(args, 15 * 1000);
138:
139: JDialog optionsDialog = new JDialog(this , "SVN test", false);
140: JTextPane tp = new JTextPane();
141: tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
142: tp.setText(rep.trim());
143: optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
144: CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
145: false, true, "Close");
146: //ccp.getOkButton().setIcon(Icons.OkIcon.shared10);
147: optionsDialog.add(ccp, BorderLayout.SOUTH);
148: tp.setEditable(false);
149: tp.setCaretPosition(0);
150: optionsDialog.setSize(800, 600);
151: optionsDialog.setLocationRelativeTo(this );
152: optionsDialog.setVisible(true);
153: }
154:
155: /*test public static void main(String[] aa)
156: {
157: JFrame f = new JFrame("Test");
158: f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
159: ProjectSettings props = new ProjectSettings();
160: new SVNSettingsDialog(f, props);
161: System.exit(0);
162: }*/
163: }
|