gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / composer / JRenamePanel.java @ 457
History | View | Annotate | Download (4.06 KB)
1 | 165 | jobacas | package org.gvsig.scripting.swing.impl.composer; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | import java.awt.GridBagConstraints; |
||
5 | import java.awt.GridBagLayout; |
||
6 | import java.awt.Insets; |
||
7 | |||
8 | import javax.swing.BorderFactory; |
||
9 | 369 | jjdelcerro | import javax.swing.JComponent; |
10 | 165 | jobacas | import javax.swing.JLabel; |
11 | import javax.swing.JOptionPane; |
||
12 | import javax.swing.JPanel; |
||
13 | import javax.swing.JTextField; |
||
14 | import javax.swing.border.TitledBorder; |
||
15 | |||
16 | import org.gvsig.scripting.ScriptingUnit; |
||
17 | import org.gvsig.scripting.swing.api.ScriptingUIManager; |
||
18 | 369 | jjdelcerro | import org.gvsig.scripting.swing.impl.DialogPanel; |
19 | 165 | jobacas | |
20 | 369 | jjdelcerro | public class JRenamePanel extends JPanel implements DialogPanel { |
21 | 180 | jobacas | /**
|
22 | *
|
||
23 | */
|
||
24 | private static final long serialVersionUID = 1L; |
||
25 | 457 | jbadia | private ScriptingUIManager uimanager;
|
26 | 299 | jjdelcerro | //private ScriptingManager manager;
|
27 | 180 | jobacas | private JRenameModel model;
|
28 | 165 | jobacas | private ScriptingUnit unit;
|
29 | |||
30 | JTextField oldName = null; |
||
31 | JTextField newName =null; |
||
32 | JPropertiesScript jProperties = null;
|
||
33 | |||
34 | 180 | jobacas | public JRenamePanel(ScriptingUIManager uimanager, JRenameModel model){
|
35 | 457 | jbadia | this.uimanager = uimanager;
|
36 | 299 | jjdelcerro | //this.manager = this.uimanager.getManager();
|
37 | 180 | jobacas | this.model= model;
|
38 | this.unit = model.getUnit();
|
||
39 | 165 | jobacas | |
40 | 180 | jobacas | model.setAction(JNewScriptModel.ACTION_CANCEL); |
41 | |||
42 | 165 | jobacas | setLayout(new BorderLayout()); |
43 | |||
44 | JPanel panel = new JPanel(); |
||
45 | panel.setLayout(new GridBagLayout()); |
||
46 | GridBagConstraints gbc = new GridBagConstraints(); |
||
47 | |||
48 | gbc.insets = new Insets(25,10,0,5); |
||
49 | gbc.weightx = 0.5;
|
||
50 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
51 | gbc.gridx = 0;
|
||
52 | gbc.gridy = 0;
|
||
53 | 457 | jbadia | panel.add(new JLabel(this.uimanager.getTranslation("current_name")+": "),gbc); |
54 | 165 | jobacas | gbc.gridx = 1;
|
55 | oldName = new JTextField(20); |
||
56 | oldName.setText(unit.getId()); |
||
57 | oldName.setEditable(false);
|
||
58 | panel.add(oldName, gbc); |
||
59 | |||
60 | gbc.insets = new Insets(10,10,25,5); |
||
61 | gbc.gridx = 0;
|
||
62 | gbc.gridy = 1;
|
||
63 | 457 | jbadia | panel.add(new JLabel(this.uimanager.getTranslation("new_name")+": "),gbc); |
64 | 165 | jobacas | gbc.gridx = 1;
|
65 | newName = new JTextField(20); |
||
66 | newName.setText(unit.getId()); |
||
67 | panel.add(newName, gbc); |
||
68 | |||
69 | TitledBorder title;
|
||
70 | 457 | jbadia | title = BorderFactory.createTitledBorder(this.uimanager.getTranslation("rename_name_title")); |
71 | 165 | jobacas | panel.setBorder(title); |
72 | |||
73 | 171 | jobacas | jProperties = new JPropertiesScript(this.unit, false); |
74 | 165 | jobacas | TitledBorder title2;
|
75 | 457 | jbadia | title2 = BorderFactory.createTitledBorder(this.uimanager.getTranslation("more_properties")); |
76 | 165 | jobacas | jProperties.setBorder(title2); |
77 | |||
78 | add(panel,BorderLayout.NORTH);
|
||
79 | add(jProperties,BorderLayout.CENTER);
|
||
80 | } |
||
81 | |||
82 | public void actionAccept() { |
||
83 | 180 | jobacas | model.setNewName(newName.getText().trim()); |
84 | unit.setName(jProperties.name.getText().trim()); |
||
85 | unit.setDescription(jProperties.description.getText().trim()); |
||
86 | unit.setCreatedBy(jProperties.createdBy.getText().trim()); |
||
87 | unit.setVersion(jProperties.version.getText().trim()); |
||
88 | model.setUnit(this.unit);
|
||
89 | |||
90 | try {
|
||
91 | model.validate(); |
||
92 | } catch (Exception e) { |
||
93 | JOptionPane.showMessageDialog(null, e.getMessage(), "Info", JOptionPane.INFORMATION_MESSAGE); |
||
94 | return;
|
||
95 | 165 | jobacas | } |
96 | 180 | jobacas | |
97 | model.setAction(JRenameModel.ACTION_ACCEPT); |
||
98 | setVisible(false);
|
||
99 | |||
100 | // boolean success = true;
|
||
101 | // if (!newName.getText().equals("") && !newName.getText().equals(oldName.getText())){
|
||
102 | // if(unit.rename(newName.getText())){
|
||
103 | // JOptionPane.showMessageDialog(null, "Rename succesfully", "Info", JOptionPane.INFORMATION_MESSAGE);
|
||
104 | // composer.launcherRefresh();
|
||
105 | // }else{
|
||
106 | // JOptionPane.showMessageDialog(null, "There're another file with the same name on the final directory\nRename the file or select another destiny.", "Error", JOptionPane.ERROR_MESSAGE);
|
||
107 | // success = false;
|
||
108 | // }
|
||
109 | // }
|
||
110 | // unit.setName(jProperties.name.getText());
|
||
111 | // unit.setDescription(jProperties.description.getText());
|
||
112 | // unit.setCreatedBy(jProperties.createdBy.getText());
|
||
113 | // unit.setVersion(jProperties.version.getText());
|
||
114 | // if(unit instanceof ScriptingScript){
|
||
115 | // ((ScriptingScript)unit).save();
|
||
116 | // }
|
||
117 | // if(success)
|
||
118 | // setVisible(false);
|
||
119 | 165 | jobacas | } |
120 | |||
121 | public void actionApply() { |
||
122 | } |
||
123 | |||
124 | public void actionCancel() { |
||
125 | setVisible(false);
|
||
126 | } |
||
127 | |||
128 | public boolean isVisibleAccept() { |
||
129 | return true; |
||
130 | } |
||
131 | |||
132 | public boolean isVisibleApply() { |
||
133 | return false; |
||
134 | } |
||
135 | |||
136 | public boolean isVisibleCancel() { |
||
137 | return true; |
||
138 | } |
||
139 | 369 | jjdelcerro | public JComponent getJComponent() { |
140 | return this; |
||
141 | } |
||
142 | 165 | jobacas | |
143 | } |