Revision 40984
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/actions/CopyPasteLayersUtils.java | ||
---|---|---|
37 | 37 |
import org.slf4j.LoggerFactory; |
38 | 38 |
|
39 | 39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.PluginsLocator; |
|
40 | 41 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
41 | 42 |
import org.gvsig.app.extension.ProjectExtension; |
42 | 43 |
import org.gvsig.app.project.Project; |
... | ... | |
69 | 70 |
* The file which is used to save the layers |
70 | 71 |
*/ |
71 | 72 |
private static String CLIPBOARD_FILE_NAME = "gvSIG_layers_clipboard.tmp"; |
72 |
private static String CLIPBOARD_FOLDER = |
|
73 |
System.getProperty("user.home") + File.separator + "gvSIG" |
|
74 |
+ File.separator + "clipboard-layers"; |
|
75 |
|
|
76 |
static { |
|
77 |
File f = new File(CLIPBOARD_FOLDER); |
|
78 |
f.mkdirs(); |
|
79 |
} |
|
73 |
private static File clipboardFolder = null; |
|
80 | 74 |
|
81 |
private static/* XML */PersistenceManager persManager = ToolsLocator |
|
82 |
.getPersistenceManager(); |
|
83 |
|
|
84 | 75 |
private CopyPasteLayersUtils() { |
85 | 76 |
} |
86 |
|
|
77 |
|
|
78 |
private static PersistenceManager getPersMan() { |
|
79 |
return ToolsLocator.getPersistenceManager(); |
|
80 |
} |
|
81 |
|
|
82 |
private static File getClipboardFolder() { |
|
83 |
if (clipboardFolder == null) { |
|
84 |
File appf = PluginsLocator.getManager().getApplicationHomeFolder(); |
|
85 |
clipboardFolder = new File(appf, "clipboard-layers"); |
|
86 |
clipboardFolder.mkdirs(); |
|
87 |
} |
|
88 |
return clipboardFolder; |
|
89 |
// |
|
90 |
|
|
91 |
} |
|
87 | 92 |
/** |
88 | 93 |
* Gets the outputstream for writing contents to the |
89 | 94 |
* clipboard |
... | ... | |
92 | 97 |
* @throws IOException |
93 | 98 |
*/ |
94 | 99 |
private static OutputStream getClipboardOStream() throws IOException { |
95 |
String strf = CLIPBOARD_FOLDER+ File.separator + CLIPBOARD_FILE_NAME; |
|
96 |
File f = new File(strf);
|
|
100 |
|
|
101 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
97 | 102 |
if (f.exists()) { |
98 | 103 |
/* |
99 | 104 |
* If file exists, it is removed |
... | ... | |
110 | 115 |
} |
111 | 116 |
|
112 | 117 |
public static void clearClipboard() throws IOException { |
113 |
String strf = CLIPBOARD_FOLDER + File.separator + CLIPBOARD_FILE_NAME; |
|
114 |
File f = new File(strf);
|
|
118 |
|
|
119 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
115 | 120 |
if (f.exists()) { |
116 | 121 |
f.delete(); |
117 | 122 |
} |
... | ... | |
125 | 130 |
* @throws IOException |
126 | 131 |
*/ |
127 | 132 |
private static InputStream getClipboardIStream() throws IOException { |
128 |
String strf = CLIPBOARD_FOLDER + File.separator + CLIPBOARD_FILE_NAME; |
|
129 |
File f = new File(strf);
|
|
133 |
|
|
134 |
File f = new File(getClipboardFolder(), CLIPBOARD_FILE_NAME);
|
|
130 | 135 |
if (f.exists()) { |
131 | 136 |
return new FileInputStream(f); |
132 | 137 |
} else { |
... | ... | |
154 | 159 |
return null; |
155 | 160 |
} |
156 | 161 |
|
157 |
Object obj = persManager.getObject(is);
|
|
162 |
Object obj = getPersMan().getObject(is);
|
|
158 | 163 |
is.close(); |
159 | 164 |
if (obj instanceof FLayers) { |
160 | 165 |
return (FLayers) obj; |
... | ... | |
181 | 186 |
OutputStream os = null; |
182 | 187 |
try { |
183 | 188 |
os = getClipboardOStream(); |
184 |
persManager.saveState(st, os);
|
|
189 |
getPersMan().saveState(st, os);
|
|
185 | 190 |
os.close(); |
186 | 191 |
if (st.getContext().getErrors() != null) { |
187 | 192 |
throw st.getContext().getErrors(); |
... | ... | |
221 | 226 |
} |
222 | 227 |
|
223 | 228 |
PersistentState state = null; |
224 |
state = persManager.getState(lyrs, true);
|
|
229 |
state = getPersMan().getState(lyrs, true);
|
|
225 | 230 |
|
226 | 231 |
if (state.getContext().getErrors() != null) { |
227 | 232 |
throw state.getContext().getErrors(); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/actions/CopyPasteDocsUtils.java | ||
---|---|---|
38 | 38 |
import org.slf4j.Logger; |
39 | 39 |
import org.slf4j.LoggerFactory; |
40 | 40 |
|
41 |
import org.gvsig.andami.PluginsLocator; |
|
41 | 42 |
import org.gvsig.app.project.documents.Document; |
42 | 43 |
import org.gvsig.tools.ToolsLocator; |
43 | 44 |
import org.gvsig.tools.persistence.PersistenceManager; |
... | ... | |
62 | 63 |
.getLogger(CopyPasteDocsUtils.class); |
63 | 64 |
|
64 | 65 |
/** |
65 |
* The file which is used to save the layers
|
|
66 |
* The folder where docs are temporarily persisted
|
|
66 | 67 |
*/ |
67 |
private static String CLIPBOARD_FOLDER = |
|
68 |
System.getProperty("user.home") |
|
69 |
+ File.separator + "gvSIG" |
|
70 |
+ File.separator + "clipboard-documents"; |
|
68 |
private static File clipboardFolder = null; |
|
71 | 69 |
private static String CLIPBOARD_FILE_NAME_PREFIX = "gvSIG_docs_clipboard_"; |
72 | 70 |
private static String CLIPBOARD_FILE_NAME_EXTENSION = "tmp"; |
73 | 71 |
private static int MAX_FILE_COUNT = 1000; |
74 | 72 |
|
75 |
private static/* XML */PersistenceManager persManager = ToolsLocator
|
|
76 |
.getPersistenceManager();
|
|
73 |
private CopyPasteDocsUtils() {
|
|
74 |
}
|
|
77 | 75 |
|
78 |
static { |
|
79 |
File file = new File(CLIPBOARD_FOLDER); |
|
80 |
file.mkdirs(); |
|
76 |
private static PersistenceManager getPersMan() { |
|
77 |
return ToolsLocator.getPersistenceManager(); |
|
81 | 78 |
} |
82 |
|
|
83 |
private CopyPasteDocsUtils() { |
|
79 |
|
|
80 |
private static File getClipboardFolder() { |
|
81 |
if (clipboardFolder == null) { |
|
82 |
File appf = PluginsLocator.getManager().getApplicationHomeFolder(); |
|
83 |
clipboardFolder = new File(appf, "clipboard-documents"); |
|
84 |
clipboardFolder.mkdirs(); |
|
85 |
} |
|
86 |
return clipboardFolder; |
|
84 | 87 |
} |
85 | 88 |
|
86 | 89 |
/** |
... | ... | |
96 | 99 |
filebase = filebase + typeName; |
97 | 100 |
} |
98 | 101 |
|
99 |
File folder = new File(CLIPBOARD_FOLDER);
|
|
102 |
File folder = getClipboardFolder();
|
|
100 | 103 |
|
101 | 104 |
if (!folder.exists() || !folder.isDirectory()) { |
102 | 105 |
return resp; |
... | ... | |
111 | 114 |
return resp; |
112 | 115 |
} |
113 | 116 |
|
114 |
/** |
|
115 |
* Returns null if not file exists |
|
116 |
* |
|
117 |
* @param docTypeName |
|
118 |
* @return |
|
119 |
* @throws IOException |
|
120 |
*/ |
|
121 |
/* |
|
122 |
private static File getFirstClipboardFile(String docTypeName) |
|
123 |
throws IOException { |
|
124 |
|
|
125 |
if (docTypeName == null || docTypeName.length() == 0) { |
|
126 |
throw new IOException("Doc type name cannot be empty"); |
|
127 |
} |
|
128 |
|
|
129 |
String filebase = System.getProperty("user.home") |
|
130 |
+ File.separator + "gvSIG" + File.separator |
|
131 |
+ CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_0." |
|
132 |
+ CLIPBOARD_FILE_NAME_EXTENSION; |
|
133 |
File resp = new File(filebase); |
|
134 |
if (resp.exists()) { |
|
135 |
return resp; |
|
136 |
} else { |
|
137 |
return null; |
|
138 |
} |
|
139 |
} |
|
140 |
*/ |
|
141 | 117 |
|
142 | 118 |
private static File getFirstUnusedClipboardFile(String docTypeName) |
143 | 119 |
throws IOException { |
... | ... | |
146 | 122 |
throw new IOException("Doc type name cannot be empty"); |
147 | 123 |
} |
148 | 124 |
|
149 |
String filebase = null;
|
|
125 |
String filename = null;
|
|
150 | 126 |
for (int i=0; i<MAX_FILE_COUNT; i++) { |
151 |
filebase = CLIPBOARD_FOLDER + File.separator |
|
152 |
+ CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_" + |
|
127 |
filename = CLIPBOARD_FILE_NAME_PREFIX + docTypeName + "_" + |
|
153 | 128 |
Integer.toString(i) |
154 | 129 |
+ "." + CLIPBOARD_FILE_NAME_EXTENSION; |
155 |
File resp = new File(filebase);
|
|
130 |
File resp = new File(getClipboardFolder(), filename);
|
|
156 | 131 |
if (!resp.exists()) { |
157 | 132 |
/* |
158 | 133 |
* Removed when JVM terminates |
... | ... | |
178 | 153 |
filebase = filebase + docTypeName; |
179 | 154 |
} |
180 | 155 |
|
181 |
File folder = new File(CLIPBOARD_FOLDER);
|
|
156 |
File folder = getClipboardFolder();
|
|
182 | 157 |
|
183 | 158 |
if (!folder.exists() || !folder.isDirectory()) { |
184 | 159 |
/* |
... | ... | |
232 | 207 |
for (int i=0; i<ff.size(); i++) { |
233 | 208 |
infile = ff.get(i); |
234 | 209 |
is = new FileInputStream(infile); |
235 |
obj = persManager.getObject(is);
|
|
210 |
obj = getPersMan().getObject(is);
|
|
236 | 211 |
is.close(); |
237 | 212 |
if (obj instanceof Document) { |
238 | 213 |
doc = (Document) obj; |
... | ... | |
299 | 274 |
PersistentState state = null; |
300 | 275 |
|
301 | 276 |
for (int i=0; i<docs.size(); i++) { |
302 |
state = persManager.getState(docs.get(i), true);
|
|
277 |
state = getPersMan().getState(docs.get(i), true);
|
|
303 | 278 |
if (state.getContext().getErrors() != null) { |
304 | 279 |
throw state.getContext().getErrors(); |
305 | 280 |
} |
306 | 281 |
f = getFirstUnusedClipboardFile(typeName); |
307 | 282 |
os = new FileOutputStream(f); |
308 |
persManager.saveState(state, os);
|
|
283 |
getPersMan().saveState(state, os);
|
|
309 | 284 |
os.close(); |
310 | 285 |
} |
311 | 286 |
} |
Also available in: Unified diff