Revision a39e5b47 web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java

b/web_client/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java
35 35
package gr.grnet.pithos.web.client;
36 36

  
37 37
import com.google.gwt.core.client.Scheduler;
38
import com.google.gwt.json.client.JSONArray;
39
import com.google.gwt.json.client.JSONString;
40
import com.google.gwt.user.client.ui.Anchor;
41
import com.google.gwt.user.client.ui.Label;
38 42
import gr.grnet.pithos.web.client.foldertree.File;
39 43
import gr.grnet.pithos.web.client.foldertree.Resource;
40 44
import gr.grnet.pithos.web.client.rest.PostCommand;
45
import gr.grnet.pithos.web.client.rest.PostRequest;
41 46
import gr.grnet.pithos.web.client.rest.PutRequest;
42 47
import gr.grnet.pithos.web.client.rest.RestException;
43 48

  
......
62 67
import com.google.gwt.user.client.ui.HorizontalPanel;
63 68
import com.google.gwt.user.client.ui.TextBox;
64 69
import com.google.gwt.user.client.ui.VerticalPanel;
70
import gr.grnet.pithos.web.client.tagtree.Tag;
71
import java.util.Iterator;
65 72

  
66 73
/**
67 74
 * The 'File properties' dialog box implementation.
......
170 177

  
171 178
        focusPanel.setFocus(true);
172 179
        setWidget(outer);
173

  
174
		// Asynchronously retrieve the tags defined by this user.
175
		DeferredCommand.addCommand(new Command() {
176

  
177
			@Override
178
			public void execute() {
179
//				updateTags();
180
			}
181
		});
182 180
	}
183 181

  
184 182
    private VerticalPanel createGeneralPanel() {
......
188 186
        generalTable.setText(1, 0, "Folder");
189 187
        generalTable.setText(2, 0, "Owner");
190 188
        generalTable.setText(3, 0, "Last modified");
191
//        generalTable.setText(4, 0, "Tags");
189
        generalTable.setText(4, 0, "Tags");
192 190

  
193 191
        name.setWidth("100%");
194 192
        name.setText(file.getName());
......
202 200
        final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
203 201
        generalTable.setText(3, 1, formatter.format(file.getLastModified()));
204 202

  
205
		// Get the tags.
206
//		StringBuffer tagsBuffer = new StringBuffer();
207
//		Iterator i = file.getTags().iterator();
208
//		while (i.hasNext()) {
209
//			String tag = (String) i.next();
210
//			tagsBuffer.append(tag).append(", ");
211
//		}
212
//		if (tagsBuffer.length() > 1)
213
//			tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
214
//		initialTagText = tagsBuffer.toString();
215
//		tags.setWidth("100%");
216
//		tags.getElement().setId("filePropertiesDialog.textBox.tags");
217
//		tags.setText(initialTagText);
218
//		generalTable.setWidget(4, 1, tags);
203
		StringBuffer tagsBuffer = new StringBuffer();
204
        for (String t : file.getTags())
205
			tagsBuffer.append(t).append(", ");
206
		if (tagsBuffer.length() > 1)
207
			tagsBuffer.delete(tagsBuffer.length() - 2, tagsBuffer.length() - 1);
208
		initialTagText = tagsBuffer.toString();
209
		tags.setWidth("100%");
210
		tags.setText(initialTagText);
211
		generalTable.setWidget(4, 1, tags);
219 212

  
220 213
        generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels");
221 214
        generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels");
222 215
        generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels");
223 216
        generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels");
224
//        generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
217
        generalTable.getFlexCellFormatter().setStyleName(4, 0, "props-labels");
225 218
        generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values");
226 219
        generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values");
227 220
        generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values");
228 221
        generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values");
229
//        generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
222
        generalTable.getFlexCellFormatter().setStyleName(4, 1, "props-values");
230 223
        generalTable.setCellSpacing(4);
231 224

  
232 225
        generalPanel.add(generalTable);
......
234 227
        DisclosurePanel allTags = new DisclosurePanel("All tags");
235 228
        allTagsContent = new FlowPanel();
236 229
        allTagsContent.setWidth("100%");
230
        for (Tag t : app.getAllTags()) {
231
            final Anchor tagAnchor = new Anchor(t.getName(), false);
232
            tagAnchor.addStyleName("pithos-tag");
233
            allTagsContent.add(tagAnchor);
234
            Label separator = new Label(", ");
235
            separator.addStyleName("pithos-tag");
236
            allTagsContent.add(separator);
237
            tagAnchor.addClickHandler(new ClickHandler() {
238

  
239
                @Override
240
                public void onClick(ClickEvent event) {
241
                    String existing = tags.getText().trim();
242
                    if (MULTIPLE_VALUES_TEXT.equals(existing))
243
                        existing = "";
244
                    String newTag = tagAnchor.getText().trim();
245
                    // insert the new tag only if it is not in the list
246
                    // already
247
                    if (existing.indexOf(newTag) == -1)
248
                        tags.setText(existing + (existing.length() > 0 ? ", " : "") + newTag);
249
                }
250
            });
251
        }
237 252
        allTags.setContent(allTagsContent);
238 253
        generalPanel.add(allTags);
239 254
        generalPanel.setSpacing(4);
......
389 404
//		permList.updatePermissionsAccordingToInput();
390 405
//		Set<PermissionHolder> perms = permList.getPermissions();
391 406
//		JSONObject json = new JSONObject();
392
		if (!name.getText().equals(file.getName())) {
393
			newFilename = name.getText();
407
		if (!name.getText().trim().equals(file.getName())) {
408
			newFilename = name.getText().trim();
394 409
//			json.put("name", new JSONString(newFilename));
395 410
		}
396 411
//		if (versioned.getValue() != file.isVersioned())
......
418 433
//			}
419 434
//			json.put("permissions", perma);
420 435
//		}
421
//		JSONArray taga = new JSONArray();
422
//		i = 0;
423
//		if (!tags.getText().equals(initialTagText)) {
424
//			String[] tagset = tags.getText().split(",");
425
//			for (String t : tagset) {
426
//				JSONString to = new JSONString(t);
427
//				taga.set(i, to);
428
//				i++;
429
//			}
430
//			json.put("tags", taga);
431
//		}
436
        String[] tagset = null;
437
		if (!tags.getText().equals(initialTagText))
438
			tagset = tags.getText().split(",");
432 439
//		String jsonString = json.toString();
433 440
//		if(jsonString.equals("{}")){
434 441
//			GWT.log("NO CHANGES", null);
435 442
//			return;
436 443
//		}
437
		final String newFilenameFinal = newFilename;
444
        final String[] newTags = tagset;
445

  
446
        if (newFilename != null) {
447
            final String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename;
448
            PutRequest updateFile = new PutRequest(path) {
449
                @Override
450
                public void onSuccess(Resource result) {
451
                    if (newTags != null)
452
                        updateMetaData(path + "?update=", newTags);
453
                    else
454
                        app.updateFolder(file.getParent());
455
                }
456

  
457
                @Override
458
                public void onError(Throwable t) {
459
                    GWT.log("", t);
460
                    app.displayError("System error modifying file:" + t.getMessage());
461
                }
462
            };
463
            updateFile.setHeader("X-Auth-Token", app.getToken());
464
            updateFile.setHeader("X-Move-From", file.getUri());
465
            updateFile.setHeader("Content-Type", file.getContentType());
466
            Scheduler.get().scheduleDeferred(updateFile);
467
        }
468
        else if (newTags != null)
469
            updateMetaData(app.getApiPath() + app.getUsername() + file.getUri() + "?update=", newTags);
470
	}
438 471

  
439
        if (newFilename == null)
440
            return;
441
        String path = app.getApiPath() + app.getUsername() + file.getParent().getUri() + "/" + newFilename;
442
        PutRequest updateFile = new PutRequest(path) {
472
    private void updateMetaData(String path, String[] newTags) {
473
        PostRequest updateFile = new PostRequest(path) {
443 474
            @Override
444 475
            public void onSuccess(Resource result) {
445 476
                app.updateFolder(file.getParent());
......
452 483
            }
453 484
        };
454 485
        updateFile.setHeader("X-Auth-Token", app.getToken());
455
        updateFile.setHeader("X-Move-From", file.getUri());
456
        updateFile.setHeader("Content-Type", file.getContentType());
486
        for (String t : newTags)
487
            updateFile.setHeader("X-Object-Meta-" + t.trim(), "true");
457 488
        Scheduler.get().scheduleDeferred(updateFile);
458
	}
489
    }
459 490

  
460 491
	private void removeAllOldVersions() {
461 492
		JSONObject json = new JSONObject();

Also available in: Unified diff