21 package net.squiz.matrix.core;
23 import net.squiz.matrix.matrixtree.*;
24 import net.squiz.matrix.assetmap.*;
26 import java.io.IOException;
27 import javax.swing.SwingUtilities;
28 import net.squiz.matrix.ui.*;
29 import net.squiz.matrix.debug.*;
30 import java.net.MalformedURLException;
62 String typeCode = evt.getTypeCode();
64 int index = evt.getIndex();
68 if (parent.getChildCount() > 0) {
70 if (index >= parent.getChildCount()) {
71 index = parent.getChildCount()-1;
74 index = (((
MatrixTreeNode)parent.getChildAt(index)).getSortOrder())+modifier;
78 String xml =
"<command action=\"get url\" cmd=\"add\" " +
79 "parent_assetid=\"" + parentAssetid +
80 "\" pos=\"" + index +
"\" type_code=\"" +
83 Document response = null;
84 MatrixStatusBar.setStatus(
Matrix.
translate(
"asset_map_status_bar_requesting"));
88 }
catch (IOException ioe) {
89 Object[] transArgs = { ioe.getMessage() };
91 MatrixStatusBar.setStatusAndClear(
Matrix.
translate(
"asset_map_error_request_failed"), 1000);
92 Log.log(
"Request for new Asset failed",
MatrixTreeComm.class, ioe);
96 MatrixStatusBar.setStatusAndClear(
Matrix.
translate(
"asset_map_status_bar_success"), 1000);
97 NodeList children = response.getDocumentElement().getChildNodes();
99 for (
int i = 0; i < children.getLength(); i++) {
100 if (!(children.item(i) instanceof Element))
102 Element element = (Element) children.item(i);
103 if (element.getTagName().equals(
"url")) {
104 url = element.getFirstChild().getNodeValue();
108 AssetMap.getURL(url);
109 }
catch (MalformedURLException mue) {
110 Log.log(
"Could not load new asset interface in right pane",
MatrixTreeComm.class, mue);
127 final String linkType,
132 final String[] parentIds) {
135 if (_parent instanceof ExpandingNode) {
136 if (_parent instanceof ExpandingNextNode) {
144 final int index = _index;
147 final String[] assetids =
new String[] { parent.
getAsset().getId() };
148 AssetRefreshWorker worker =
new AssetRefreshWorker(assetids,
true) {
149 public Object construct() {
151 int newIndex = index;
152 if (!parent.
getAsset().getId().equals(
"1")) {
155 if (index >= limit) {
159 if (parent.
getAsset().getTotalKidsLoaded() == 0) {
162 newIndex = ((
MatrixTreeNode)parent.getChildAt(limit-modifier)).getSortOrder() + children.length;
164 }
else if ((index <= 0) && (parent.
getAsset().getTotalKidsLoaded() > 0)) {
165 if (parent.getChildCount() > 0) {
167 newIndex = ((
MatrixTreeNode)parent.getChildAt(1)).getSortOrder() - children.length;
169 }
else if (index >= 0) {
170 if (parent.getChildCount() > index) {
171 newIndex = ((
MatrixTreeNode)parent.getChildAt(index)).getSortOrder();
172 }
else if (parent.getChildCount() > 0) {
173 newIndex = ((
MatrixTreeNode)parent.getChildAt(parent.getChildCount()-1)).getSortOrder()+1;
178 Boolean refresh = doLinkRequest(
185 if (refresh == Boolean.TRUE) {
186 String parentid = parent.
getAsset().getId();
190 }
catch (IOException ioe) {
195 public void finished() {
200 MatrixStatusBar.setStatusAndClear(
Matrix.
translate(
"asset_map_status_bar_success"), 1000);
225 private static String generateCreateLinkXML(
230 String[] parentIds) {
231 StringBuffer xml =
new StringBuffer();
232 xml.append(
"<command action=\"").append(linkType).append(
"\"");
233 xml.append(
" to_parent_assetid=\"").append(toParentId).append(
"\"");
234 xml.append(
" to_parent_pos=\"").append(index).append(
"\">");
236 for (
int i = 0; i < children.length; i++) {
239 String parentid = null;
245 }
catch (NullPointerException ex) {
246 parentid = parentIds[i];
248 xml.append(
"<asset assetid=\"").append(assetid).append(
"\" ");
249 xml.append(
" linkid=\"").append(linkid).append(
"\" ");
250 xml.append(
" parentid=\"").append(parentid).append(
"\" />");
252 xml.append(
"</command>");
254 return xml.toString();
266 private static Boolean doLinkRequest(
268 MatrixTreeNode[] children,
269 MatrixTreeNode parent,
271 String[] parentIds)
throws IOException {
278 String toParentId = MatrixToolkit.rawUrlEncode(parent.getAsset().getId(),
true);
279 String xml = generateCreateLinkXML(linkType, toParentId, children, index, parentIds);
280 Document response = Matrix.doRequest(xml);
281 NodeList childNodes = response.getDocumentElement().getChildNodes();
284 Boolean refresh = Boolean.FALSE;
286 for (
int i = 0; i < childNodes.getLength(); i++) {
287 if (!(childNodes.item(i) instanceof Element))
289 Element element = (Element) childNodes.item(i);
290 if (element.getTagName().equals(
"url")) {
291 url = element.getFirstChild().getNodeValue();
292 }
else if (element.getTagName().equals(
"success")) {
293 refresh = Boolean.TRUE;
300 AssetMap.openWindow(url,
"");