Lines 50-63
import java.beans.PropertyChangeEvent;
Link Here
|
50 |
import java.beans.PropertyChangeEvent; |
50 |
import java.beans.PropertyChangeEvent; |
51 |
import java.beans.PropertyChangeListener; |
51 |
import java.beans.PropertyChangeListener; |
52 |
import java.io.IOException; |
52 |
import java.io.IOException; |
53 |
import java.util.*; |
|
|
54 |
import java.text.MessageFormat; |
53 |
import java.text.MessageFormat; |
|
|
54 |
import java.util.List; |
55 |
import java.util.Locale; |
55 |
|
56 |
|
56 |
import org.openide.DialogDescriptor; |
57 |
import org.openide.DialogDescriptor; |
57 |
import org.openide.filesystems.FileLock; |
|
|
58 |
import org.openide.filesystems.FileObject; |
58 |
import org.openide.filesystems.FileObject; |
59 |
import org.openide.filesystems.FileUtil; |
|
|
60 |
import org.openide.loaders.DataFolder; |
61 |
import org.openide.loaders.DataNode; |
59 |
import org.openide.loaders.DataNode; |
62 |
import org.openide.loaders.DataObject; |
60 |
import org.openide.loaders.DataObject; |
63 |
import org.openide.nodes.Children; |
61 |
import org.openide.nodes.Children; |
Lines 124-131
public class PropertiesDataNode extends
Link Here
|
124 |
*/ |
122 |
*/ |
125 |
final class NameUpdater implements PropertyChangeListener { |
123 |
final class NameUpdater implements PropertyChangeListener { |
126 |
|
124 |
|
127 |
/** |
125 |
@Override |
128 |
*/ |
|
|
129 |
public void propertyChange(PropertyChangeEvent e) { |
126 |
public void propertyChange(PropertyChangeEvent e) { |
130 |
if (DataObject.PROP_FILES.equals(e.getPropertyName())) { |
127 |
if (DataObject.PROP_FILES.equals(e.getPropertyName())) { |
131 |
PropertiesDataObject propDO = (PropertiesDataObject) getDataObject(); |
128 |
PropertiesDataObject propDO = (PropertiesDataObject) getDataObject(); |
Lines 172-274
public class PropertiesDataNode extends
Link Here
|
172 |
return new BundleNodeCustomizer((PropertiesDataObject)getDataObject()); |
169 |
return new BundleNodeCustomizer((PropertiesDataObject)getDataObject()); |
173 |
} |
170 |
} |
174 |
|
171 |
|
175 |
/** Creates paste types for this node. Overrides superclass method. |
|
|
176 |
* @param transferable transferable in clipboard |
177 |
* @param types <code>PasteType</code>'s valid for this node. */ |
178 |
@Override |
172 |
@Override |
179 |
public void createPasteTypes(Transferable transferable, List<PasteType> types) { |
173 |
public void createPasteTypes(Transferable transferable, List<PasteType> types) { |
180 |
super.createPasteTypes(transferable, types); |
174 |
super.createPasteTypes(transferable, types); |
181 |
|
175 |
|
182 |
// Copy/paste mode? |
176 |
Element.ItemElem item; |
183 |
int mode = NodeTransfer.COPY; |
177 |
Node node = NodeTransfer.node(transferable, NodeTransfer.MOVE); |
184 |
|
178 |
if (node != null && node.canDestroy()) { |
185 |
Node node = NodeTransfer.node(transferable, mode); |
179 |
item = node.getCookie(Element.ItemElem.class); |
186 |
|
180 |
if (item == null || node == getChildren().findChild(item.getKey())) { |
187 |
if(node == null || !(node instanceof PropertiesLocaleNode)) { |
|
|
188 |
// Cut/paste mode? |
189 |
mode = NodeTransfer.MOVE; |
190 |
|
191 |
node = NodeTransfer.node(transferable, mode); |
192 |
|
193 |
if(node == null || !(node instanceof PropertiesLocaleNode)) |
194 |
return; |
195 |
|
196 |
PropertiesFileEntry entry = (PropertiesFileEntry)((PropertiesLocaleNode)node).getFileEntry(); |
197 |
if(((PropertiesDataObject)getDataObject()).files().contains(entry.getFile())) { |
198 |
return; |
181 |
return; |
199 |
} |
182 |
} |
|
|
183 |
types.add(new EntryPasteType(item, node)); |
184 |
} else { |
185 |
item = NodeTransfer.cookie(transferable, NodeTransfer.COPY, Element.ItemElem.class); |
186 |
if (item != null) { |
187 |
types.add(new EntryPasteType(item, null)); |
188 |
} |
189 |
} |
190 |
} |
191 |
|
192 |
/** |
193 |
* A {@link PasteType} for pasting the key nodes of properties files. This |
194 |
* class adds or updates the property key, value and comment of the copied |
195 |
* node to the properties file of this {@link PropertiesDataNode}. Also |
196 |
* destroys the copied node in case a cut action was performed. |
197 |
*/ |
198 |
private class EntryPasteType extends PasteType { |
199 |
|
200 |
/** |
201 |
* The {@link Element.ItemElem} to paste. |
202 |
*/ |
203 |
private final Element.ItemElem item; |
204 |
|
205 |
/** |
206 |
* The {@link Node} to destroy in case of a cut action. |
207 |
*/ |
208 |
private final Node node; |
209 |
|
210 |
/** |
211 |
* Creates a new instance of {@link EntryPasteType}. |
212 |
* |
213 |
* @param item the {@link Element.ItemElem} to paste |
214 |
* @param node the {@link Node} to destroy in case a cut action was |
215 |
* performed, otherwise it should be {@code null} |
216 |
*/ |
217 |
public EntryPasteType(final Element.ItemElem item, final Node node) { |
218 |
this.item = item; |
219 |
this.node = node; |
200 |
} |
220 |
} |
201 |
|
221 |
|
202 |
PropertiesFileEntry entry = (PropertiesFileEntry)((PropertiesLocaleNode)node).getFileEntry(); |
222 |
@Override |
203 |
types.add(new EntryPasteType(entry, mode)); |
223 |
public Transferable paste() throws IOException { |
204 |
} |
224 |
final PropertiesStructure properties = ((PropertiesFileEntry)((PropertiesDataObject)getDataObject()) |
|
|
225 |
.getPrimaryEntry()).getHandler().getStructure(); |
226 |
final Element.ItemElem storedItem = properties.getItem(item.getKey()); |
205 |
|
227 |
|
206 |
/** Paste type for <code>PropertiesDataNode</code>. */ |
228 |
if (storedItem == null) { |
207 |
private class EntryPasteType extends PasteType { |
229 |
properties.addItem(item.getKey(), item.getValue(), item.getComment()); |
208 |
|
230 |
} else { |
209 |
/** Entry to copy/move. */ |
231 |
storedItem.setValue(item.getValue()); |
210 |
private PropertiesFileEntry entry; |
232 |
storedItem.setComment(item.getComment()); |
211 |
|
|
|
212 |
/** Flag for copying/moving. */ |
213 |
private int flag; |
214 |
|
215 |
|
216 |
/** Constructor. |
217 |
* @param entry entry to copy/move |
218 |
* @param flag flag for moving/copying */ |
219 |
public EntryPasteType(PropertiesFileEntry entry, int flag) { |
220 |
this.entry = entry; |
221 |
this.flag = flag; |
222 |
} |
223 |
|
224 |
/** Peforms paste action. Implements superclass abstract method. |
225 |
* @exception IOException if error occured */ |
226 |
public Transferable paste() throws IOException { |
227 |
DataFolder dataFolder = PropertiesDataNode.this.getDataObject().getFolder(); |
228 |
|
229 |
if(dataFolder == null) |
230 |
return null; |
231 |
|
232 |
FileObject folder = dataFolder.getPrimaryFile(); |
233 |
|
234 |
String newName = getDataObject().getPrimaryFile().getName() + Util.getLocaleSuffix(entry); |
235 |
|
236 |
int entryIndex = ((PropertiesDataObject)getDataObject()).getBundleStructure().getEntryIndexByFileName(newName); |
237 |
|
238 |
// Has such item -> find brother. |
239 |
if(entryIndex != -1) { |
240 |
newName = FileUtil.findFreeFileName(folder, newName, entry.getFile().getExt()); |
241 |
} |
233 |
} |
242 |
|
234 |
|
243 |
if(flag == NodeTransfer.COPY) { |
235 |
if (node != null) { |
244 |
FileObject fileObject = entry.getFile(); |
236 |
node.destroy(); |
245 |
fileObject.copy(folder, newName, fileObject.getExt()); |
|
|
246 |
|
247 |
} else if(flag == NodeTransfer.MOVE) { |
248 |
FileObject fileObject = entry.getFile(); |
249 |
FileLock lock = entry.takeLock(); |
250 |
|
251 |
// removing secondary entry from original data object |
252 |
((PropertiesDataObject) entry.getDataObject()).removeSecondaryEntry2(entry); |
253 |
try { |
254 |
FileObject fo2 = fileObject.move(lock, folder, newName, fileObject.getExt()); |
255 |
try { |
256 |
// Invokes the method for recognition fo2's primary fila and data object. |
257 |
// Secondary entry in destination data object is created and registered |
258 |
DataObject.find(fo2); |
259 |
} |
260 |
catch (Exception e) { |
261 |
} |
262 |
} finally { |
263 |
lock.releaseLock (); |
264 |
} |
265 |
} |
237 |
} |
266 |
|
|
|
267 |
return null; |
238 |
return null; |
268 |
} |
239 |
} |
269 |
|
240 |
} |
270 |
} // End of class EntryPasteType. |
|
|
271 |
|
272 |
|
241 |
|
273 |
/** New type for properties node. It creates new locale for ths bundle. */ |
242 |
/** New type for properties node. It creates new locale for ths bundle. */ |
274 |
private class NewLocaleType extends NewType { |
243 |
private class NewLocaleType extends NewType { |
Lines 280-285
public class PropertiesDataNode extends
Link Here
|
280 |
} |
249 |
} |
281 |
|
250 |
|
282 |
/** Overrides superclass method. */ |
251 |
/** Overrides superclass method. */ |
|
|
252 |
@Override |
283 |
public void create() throws IOException { |
253 |
public void create() throws IOException { |
284 |
final PropertiesDataObject propertiesDataObject = (PropertiesDataObject)getCookie(DataObject.class); |
254 |
final PropertiesDataObject propertiesDataObject = (PropertiesDataObject)getCookie(DataObject.class); |
285 |
|
255 |
|
Lines 293-298
public class PropertiesDataNode extends
Link Here
|
293 |
DialogDescriptor.OK_CANCEL_OPTION, |
263 |
DialogDescriptor.OK_CANCEL_OPTION, |
294 |
DialogDescriptor.OK_OPTION, |
264 |
DialogDescriptor.OK_OPTION, |
295 |
new ActionListener() { |
265 |
new ActionListener() { |
|
|
266 |
@Override |
296 |
public void actionPerformed(ActionEvent evt) { |
267 |
public void actionPerformed(ActionEvent evt) { |
297 |
if (evt.getSource() == DialogDescriptor.OK_OPTION) { |
268 |
if (evt.getSource() == DialogDescriptor.OK_OPTION) { |
298 |
if (containsLocale(propertiesDataObject, panel.getLocale())) { |
269 |
if (containsLocale(propertiesDataObject, panel.getLocale())) { |