183154c86da1aa19b810184af47163cb641eac69
[public/netxms.git] / webui / webapp / FileManager / src / org / netxms / ui / eclipse / filemanager / views / AgentFileManager.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2016 Raden Solutions
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.ui.eclipse.filemanager.views;
20
21 import java.io.File;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.net.URLEncoder;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.zip.ZipEntry;
29 import java.util.zip.ZipOutputStream;
30 import org.eclipse.core.runtime.IProgressMonitor;
31 import org.eclipse.jface.action.Action;
32 import org.eclipse.jface.action.GroupMarker;
33 import org.eclipse.jface.action.IMenuListener;
34 import org.eclipse.jface.action.IMenuManager;
35 import org.eclipse.jface.action.IToolBarManager;
36 import org.eclipse.jface.action.MenuManager;
37 import org.eclipse.jface.action.Separator;
38 import org.eclipse.jface.commands.ActionHandler;
39 import org.eclipse.jface.dialogs.IDialogSettings;
40 import org.eclipse.jface.util.LocalSelectionTransfer;
41 import org.eclipse.jface.viewers.CellEditor;
42 import org.eclipse.jface.viewers.ColumnViewerEditor;
43 import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
44 import org.eclipse.jface.viewers.ColumnViewerEditorActivationStrategy;
45 import org.eclipse.jface.viewers.ICellModifier;
46 import org.eclipse.jface.viewers.ISelectionChangedListener;
47 import org.eclipse.jface.viewers.IStructuredSelection;
48 import org.eclipse.jface.viewers.SelectionChangedEvent;
49 import org.eclipse.jface.viewers.TextCellEditor;
50 import org.eclipse.jface.viewers.TreeViewerEditor;
51 import org.eclipse.jface.viewers.ViewerDropAdapter;
52 import org.eclipse.jface.window.Window;
53 import org.eclipse.rap.rwt.RWT;
54 import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
55 import org.eclipse.swt.SWT;
56 import org.eclipse.swt.dnd.DND;
57 import org.eclipse.swt.dnd.DragSourceAdapter;
58 import org.eclipse.swt.dnd.DragSourceEvent;
59 import org.eclipse.swt.dnd.Transfer;
60 import org.eclipse.swt.dnd.TransferData;
61 import org.eclipse.swt.events.DisposeEvent;
62 import org.eclipse.swt.events.DisposeListener;
63 import org.eclipse.swt.events.ModifyEvent;
64 import org.eclipse.swt.events.ModifyListener;
65 import org.eclipse.swt.layout.FormAttachment;
66 import org.eclipse.swt.layout.FormData;
67 import org.eclipse.swt.layout.FormLayout;
68 import org.eclipse.swt.widgets.Composite;
69 import org.eclipse.swt.widgets.Display;
70 import org.eclipse.swt.widgets.Item;
71 import org.eclipse.swt.widgets.Menu;
72 import org.eclipse.ui.IActionBars;
73 import org.eclipse.ui.IViewSite;
74 import org.eclipse.ui.IWorkbenchActionConstants;
75 import org.eclipse.ui.IWorkbenchWindow;
76 import org.eclipse.ui.PartInitException;
77 import org.eclipse.ui.PlatformUI;
78 import org.eclipse.ui.contexts.IContextService;
79 import org.eclipse.ui.handlers.IHandlerService;
80 import org.eclipse.ui.part.ViewPart;
81 import org.netxms.client.AgentFileData;
82 import org.netxms.client.NXCException;
83 import org.netxms.client.NXCSession;
84 import org.netxms.client.ProgressListener;
85 import org.netxms.client.constants.RCC;
86 import org.netxms.client.objects.Node;
87 import org.netxms.client.server.AgentFile;
88 import org.netxms.ui.eclipse.actions.RefreshAction;
89 import org.netxms.ui.eclipse.console.DownloadServiceHandler;
90 import org.netxms.ui.eclipse.console.resources.SharedIcons;
91 import org.netxms.ui.eclipse.filemanager.Activator;
92 import org.netxms.ui.eclipse.filemanager.Messages;
93 import org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog;
94 import org.netxms.ui.eclipse.filemanager.dialogs.StartClientToServerFileUploadDialog;
95 import org.netxms.ui.eclipse.filemanager.views.helpers.AgentFileComparator;
96 import org.netxms.ui.eclipse.filemanager.views.helpers.AgentFileFilter;
97 import org.netxms.ui.eclipse.filemanager.views.helpers.AgentFileLabelProvider;
98 import org.netxms.ui.eclipse.filemanager.views.helpers.ViewAgentFilesProvider;
99 import org.netxms.ui.eclipse.jobs.ConsoleJob;
100 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
101 import org.netxms.ui.eclipse.tools.DialogData;
102 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
103 import org.netxms.ui.eclipse.tools.WidgetHelper;
104 import org.netxms.ui.eclipse.widgets.FilterText;
105 import org.netxms.ui.eclipse.widgets.SortableTableViewer;
106 import org.netxms.ui.eclipse.widgets.SortableTreeViewer;
107
108 /**
109 * File manager for agent files
110 */
111 public class AgentFileManager extends ViewPart
112 {
113 public static final String ID = "org.netxms.ui.eclipse.filemanager.views.AgentFileManager"; //$NON-NLS-1$
114
115 private static final String TABLE_CONFIG_PREFIX = "AgentFileManager"; //$NON-NLS-1$
116
117 // Columns
118 public static final int COLUMN_NAME = 0;
119 public static final int COLUMN_TYPE = 1;
120 public static final int COLUMN_SIZE = 2;
121 public static final int COLUMN_MODIFYED = 3;
122 public static final int COLUMN_OWNER = 4;
123 public static final int COLUMN_GROUP = 5;
124 public static final int COLUMN_ACCESS_RIGHTS = 6;
125
126 private boolean initShowFilter = true;
127 private Composite content;
128 private AgentFileFilter filter;
129 private FilterText filterText;
130 private SortableTreeViewer viewer;
131 private NXCSession session;
132 private Action actionRefreshAll;
133 private Action actionUploadFile;
134 private Action actionDelete;
135 private Action actionRename;
136 private Action actionRefreshDirectory;
137 private Action actionShowFilter;
138 private Action actionDownloadFile;
139 private Action actionTailFile;
140 private Action actionShowFile;
141 private Action actionCreateDirectory;
142 private Action actionCalculateFolderSize;
143 private Action actionCopyFilePath;
144 private Action actionCopyFileName;
145 private long objectId = 0;
146
147 /*
148 * (non-Javadoc)
149 *
150 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
151 */
152 @Override
153 public void init(IViewSite site) throws PartInitException
154 {
155 super.init(site);
156
157 session = (NXCSession)ConsoleSharedData.getSession();
158 IDialogSettings settings = Activator.getDefault().getDialogSettings();
159 initShowFilter = safeCast(settings.get("AgentFileManager.showFilter"), settings.getBoolean("AgentFileManager.showFilter"), initShowFilter);
160 objectId = Long.parseLong(site.getSecondaryId());
161 setPartName(String.format(Messages.get().AgentFileManager_PartTitle, session.getObjectName(objectId)));
162 }
163
164 /**
165 * @param b
166 * @param defval
167 * @return
168 */
169 private static boolean safeCast(String s, boolean b, boolean defval)
170 {
171 return (s != null) ? b : defval;
172 }
173
174 /*
175 * (non-Javadoc)
176 *
177 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
178 */
179 @Override
180 public void createPartControl(Composite parent)
181 {
182 content = new Composite(parent, SWT.NONE);
183 content.setLayout(new FormLayout());
184
185 // Create filter area
186 filterText = new FilterText(content, SWT.NONE);
187 filterText.addModifyListener(new ModifyListener() {
188 @Override
189 public void modifyText(ModifyEvent e)
190 {
191 onFilterModify();
192 }
193 });
194
195 String os = ((Node)session.findObjectById(objectId)).getSystemDescription(); //$NON-NLS-1$
196
197 if (os.contains("Windows")) //if OS is windows don't show group and access rights columns //$NON-NLS-1$
198 {
199 final String[] columnNames = { Messages.get().AgentFileManager_ColName, Messages.get().AgentFileManager_ColType, Messages.get().AgentFileManager_ColSize, Messages.get().AgentFileManager_ColDate, Messages.get().AgentFileManager_ColOwner };
200 final int[] columnWidths = { 300, 120, 150, 150, 150 };
201 viewer = new SortableTreeViewer(content, columnNames, columnWidths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
202 }
203 else
204 {
205 final String[] columnNames = { Messages.get().AgentFileManager_ColName, Messages.get().AgentFileManager_ColType, Messages.get().AgentFileManager_ColSize, Messages.get().AgentFileManager_ColDate, Messages.get().AgentFileManager_ColOwner, Messages.get().AgentFileManager_ColGroup, Messages.get().AgentFileManager_ColAccessRights };
206 final int[] columnWidths = { 300, 120, 150, 150, 150, 150, 200 };
207 viewer = new SortableTreeViewer(content, columnNames, columnWidths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
208 }
209
210 WidgetHelper.restoreTreeViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
211 viewer.setContentProvider(new ViewAgentFilesProvider());
212 viewer.setLabelProvider(new AgentFileLabelProvider());
213 viewer.setComparator(new AgentFileComparator());
214 filter = new AgentFileFilter();
215 viewer.addFilter(filter);
216 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
217 @Override
218 public void selectionChanged(SelectionChangedEvent event)
219 {
220 IStructuredSelection selection = (IStructuredSelection)event.getSelection();
221 if (selection != null)
222 {
223 actionDelete.setEnabled(selection.size() > 0);
224 actionCalculateFolderSize.setEnabled(selection.size() > 0);
225 }
226 }
227 });
228 viewer.getTree().addDisposeListener(new DisposeListener() {
229 @Override
230 public void widgetDisposed(DisposeEvent e)
231 {
232 WidgetHelper.saveTreeViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
233 }
234 });
235 enableDragSupport();
236 enableDropSupport();
237 enableInPlaceRename();
238
239 // Setup layout
240 FormData fd = new FormData();
241 fd.left = new FormAttachment(0, 0);
242 fd.top = new FormAttachment(filterText);
243 fd.right = new FormAttachment(100, 0);
244 fd.bottom = new FormAttachment(100, 0);
245 viewer.getTree().setLayoutData(fd);
246
247 fd = new FormData();
248 fd.left = new FormAttachment(0, 0);
249 fd.top = new FormAttachment(0, 0);
250 fd.right = new FormAttachment(100, 0);
251 filterText.setLayoutData(fd);
252
253 createActions();
254 contributeToActionBars();
255 createPopupMenu();
256 activateContext();
257
258 filterText.setCloseAction(actionShowFilter);
259
260 // Set initial focus to filter input line
261 if (initShowFilter)
262 filterText.setFocus();
263 else
264 enableFilter(false); // Will hide filter area correctly
265
266 refreshFileList();
267 }
268
269 /* (non-Javadoc)
270 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
271 */
272 @Override
273 public void dispose()
274 {
275 IDialogSettings settings = Activator.getDefault().getDialogSettings();
276 settings.put("AgentFileManager.showFilter", initShowFilter);
277 super.dispose();
278 }
279
280 /**
281 * Activate context
282 */
283 private void activateContext()
284 {
285 IContextService contextService = (IContextService)getSite().getService(IContextService.class);
286 if (contextService != null)
287 {
288 contextService.activateContext("org.netxms.ui.eclipse.filemanager.context.FileManager"); //$NON-NLS-1$
289 }
290 }
291
292 /**
293 * Enable drag support in object tree
294 */
295 public void enableDragSupport()
296 {
297 Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
298 viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new DragSourceAdapter() {
299 @Override
300 public void dragStart(DragSourceEvent event)
301 {
302 LocalSelectionTransfer.getTransfer().setSelection(viewer.getSelection());
303 event.doit = true;
304 }
305
306 @Override
307 public void dragSetData(DragSourceEvent event)
308 {
309 event.data = LocalSelectionTransfer.getTransfer().getSelection();
310 }
311 });
312 }
313
314 /**
315 * Enable drop support in object tree
316 */
317 public void enableDropSupport()// SubtreeType infrastructure
318 {
319 final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
320 viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(viewer) {
321
322 @Override
323 public boolean performDrop(Object data)
324 {
325 IStructuredSelection selection = (IStructuredSelection)data;
326 List<?> movableSelection = selection.toList();
327 for(int i = 0; i < movableSelection.size(); i++)
328 {
329 AgentFile movableObject = (AgentFile)movableSelection.get(i);
330
331 moveFile((AgentFile)getCurrentTarget(), movableObject);
332
333 }
334 return true;
335 }
336
337 @Override
338 public boolean validateDrop(Object target, int operation, TransferData transferType)
339 {
340 if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
341 return false;
342
343 IStructuredSelection selection = (IStructuredSelection)LocalSelectionTransfer.getTransfer().getSelection();
344 if (selection.isEmpty())
345 return false;
346
347 for(final Object object : selection.toList())
348 {
349 if (!(object instanceof AgentFile))
350 return false;
351 }
352 if (!(target instanceof AgentFile))
353 {
354 return false;
355 }
356 else
357 {
358 if (!((AgentFile)target).isDirectory())
359 {
360 return false;
361 }
362 }
363 return true;
364 }
365 });
366 }
367
368 /**
369 * Enable in-place renames
370 */
371 private void enableInPlaceRename()
372 {
373 TreeViewerEditor.create(viewer, new ColumnViewerEditorActivationStrategy(viewer) {
374 @Override
375 protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event)
376 {
377 return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
378 }
379 }, ColumnViewerEditor.DEFAULT);
380 viewer.setCellEditors(new CellEditor[] { new TextCellEditor(viewer.getTree()) });
381 viewer.setColumnProperties(new String[] { "name" }); //$NON-NLS-1$
382 viewer.setCellModifier(new ICellModifier() {
383 @Override
384 public void modify(Object element, String property, Object value)
385 {
386 if (element instanceof Item)
387 element = ((Item)element).getData();
388
389 if (property.equals("name")) //$NON-NLS-1$
390 {
391 if (element instanceof AgentFile)
392 {
393 doRename((AgentFile)element, value.toString());
394 }
395 }
396 }
397
398 @Override
399 public Object getValue(Object element, String property)
400 {
401 if (property.equals("name")) //$NON-NLS-1$
402 {
403 if (element instanceof AgentFile)
404 {
405 return ((AgentFile)element).getName();
406 }
407 }
408 return null;
409 }
410
411 @Override
412 public boolean canModify(Object element, String property)
413 {
414 return property.equals("name"); //$NON-NLS-1$
415 }
416 });
417 }
418
419 /**
420 * Do actual rename
421 *
422 * @param AgentFile
423 * @param newName
424 */
425 private void doRename(final AgentFile agentFile, final String newName)
426 {
427 new ConsoleJob("Rename file", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
428 @Override
429 protected String getErrorMessage()
430 {
431 return Messages.get().AgentFileManager_RenameError;
432 }
433
434 @Override
435 protected void runInternal(IProgressMonitor monitor) throws Exception
436 {
437 final NestedVerifyOverwrite verify = new NestedVerifyOverwrite(agentFile.getType(), newName, true, true, false) {
438
439 @Override
440 public void executeAction() throws NXCException, IOException
441 {
442 session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, false); //$NON-NLS-1$
443 }
444
445 @Override
446 public void executeSameFunctionWithOverwrite() throws IOException, NXCException
447 {
448 session.renameAgentFile(objectId, agentFile.getFullName(), agentFile.getParent().getFullName() + "/" + newName, true); //$NON-NLS-1$
449 }
450 };
451 verify.run(viewer.getControl().getDisplay());
452
453 if(verify.isOkPressed())
454 {
455 runInUIThread(new Runnable() {
456 @Override
457 public void run()
458 {
459 if(verify.isOkPressed())
460 refreshFileOrDirectory();
461 agentFile.setName(newName);
462 viewer.refresh(agentFile, true);
463 }
464 });
465 }
466 }
467 }.start();
468 }
469
470 /**
471 * Create actions
472 */
473 private void createActions()
474 {
475 final IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
476
477 actionRefreshDirectory = new Action(Messages.get().AgentFileManager_RefreshFolder, SharedIcons.REFRESH) {
478 @Override
479 public void run()
480 {
481 refreshFileOrDirectory();
482 }
483 };
484 actionRefreshDirectory.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.refreshFolder"); //$NON-NLS-1$
485 handlerService.activateHandler(actionRefreshDirectory.getActionDefinitionId(), new ActionHandler(actionRefreshDirectory));
486
487 actionRefreshAll = new RefreshAction(this) {
488 @Override
489 public void run()
490 {
491 refreshFileList();
492 }
493 };
494
495 actionUploadFile = new Action(Messages.get().AgentFileManager_UploadFile) {
496 @Override
497 public void run()
498 {
499 uploadFile(false);
500 }
501 };
502 actionUploadFile.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.uploadFile"); //$NON-NLS-1$
503 handlerService.activateHandler(actionUploadFile.getActionDefinitionId(), new ActionHandler(actionUploadFile));
504
505 actionDelete = new Action(Messages.get().AgentFileManager_Delete, SharedIcons.DELETE_OBJECT) {
506 @Override
507 public void run()
508 {
509 deleteFile();
510 }
511 };
512 actionDelete.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.delete"); //$NON-NLS-1$
513 handlerService.activateHandler(actionDelete.getActionDefinitionId(), new ActionHandler(actionDelete));
514
515 actionRename = new Action(Messages.get().AgentFileManager_Rename) {
516 @Override
517 public void run()
518 {
519 renameFile();
520 }
521 };
522 actionRename.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.rename"); //$NON-NLS-1$
523 handlerService.activateHandler(actionRename.getActionDefinitionId(), new ActionHandler(actionRename));
524
525 actionShowFilter = new Action(Messages.get().ViewServerFile_ShowFilterAction, Action.AS_CHECK_BOX) {
526 @Override
527 public void run()
528 {
529 enableFilter(!initShowFilter);
530 actionShowFilter.setChecked(initShowFilter);
531 }
532 };
533 actionShowFilter.setChecked(initShowFilter);
534 actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.showFilter"); //$NON-NLS-1$
535 handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), new ActionHandler(actionShowFilter));
536
537 actionDownloadFile = new Action(Messages.get().AgentFileManager_Download) {
538 @Override
539 public void run()
540 {
541 startDownload();
542 }
543 };
544 actionDownloadFile.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.download"); //$NON-NLS-1$
545 handlerService.activateHandler(actionDownloadFile.getActionDefinitionId(), new ActionHandler(actionDownloadFile));
546
547 actionTailFile = new Action(Messages.get().AgentFileManager_FollowChanges) {
548 @Override
549 public void run()
550 {
551 tailFile(true, 1024);
552 }
553 };
554
555 actionShowFile = new Action(Messages.get().AgentFileManager_Show) {
556 @Override
557 public void run()
558 {
559 tailFile(false, 0);
560 }
561 };
562
563 actionCreateDirectory = new Action(Messages.get().AgentFileManager_CreateFolder) {
564 @Override
565 public void run()
566 {
567 createFolder();
568 }
569 };
570 actionCreateDirectory.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.newFolder"); //$NON-NLS-1$
571 handlerService.activateHandler(actionCreateDirectory.getActionDefinitionId(), new ActionHandler(actionCreateDirectory));
572
573 actionCalculateFolderSize = new Action("Calculate folder &size") {
574 @Override
575 public void run()
576 {
577 calculateFolderSize();
578 }
579 };
580 actionCalculateFolderSize.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.calculateFolderSize"); //$NON-NLS-1$
581 handlerService.activateHandler(actionCalculateFolderSize.getActionDefinitionId(), new ActionHandler(actionCalculateFolderSize));
582
583 actionCopyFileName = new Action("Copy file &name") {
584 @Override
585 public void run()
586 {
587 copyFileName();
588 }
589 };
590 actionCopyFileName.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.copyFileName"); //$NON-NLS-1$
591 handlerService.activateHandler(actionCopyFileName.getActionDefinitionId(), new ActionHandler(actionCopyFileName));
592
593 actionCopyFilePath = new Action("Copy file &path") {
594 @Override
595 public void run()
596 {
597 copyFilePath();
598 }
599 };
600 actionCopyFilePath.setActionDefinitionId("org.netxms.ui.eclipse.filemanager.commands.copyFilePath"); //$NON-NLS-1$
601 handlerService.activateHandler(actionCopyFilePath.getActionDefinitionId(), new ActionHandler(actionCopyFilePath));
602 }
603
604 /**
605 * Contribute actions to action bar
606 */
607 private void contributeToActionBars()
608 {
609 IActionBars bars = getViewSite().getActionBars();
610 fillLocalPullDown(bars.getMenuManager());
611 fillLocalToolBar(bars.getToolBarManager());
612 }
613
614 /**
615 * Fill local pull-down menu
616 *
617 * @param manager Menu manager for pull-down menu
618 */
619 private void fillLocalPullDown(IMenuManager manager)
620 {
621 manager.add(actionShowFilter);
622 manager.add(new Separator());
623 manager.add(actionRefreshAll);
624 }
625
626 /**
627 * Fill local tool bar
628 *
629 * @param manager Menu manager for local tool bar
630 */
631 private void fillLocalToolBar(IToolBarManager manager)
632 {
633 manager.add(actionRefreshAll);
634 }
635
636 /**
637 * Create pop-up menu for user list
638 */
639 private void createPopupMenu()
640 {
641 // Create menu manager
642 MenuManager menuMgr = new MenuManager();
643 menuMgr.setRemoveAllWhenShown(true);
644 menuMgr.addMenuListener(new IMenuListener() {
645 public void menuAboutToShow(IMenuManager mgr)
646 {
647 fillContextMenu(mgr);
648 }
649 });
650
651 // Create menu
652 Menu menu = menuMgr.createContextMenu(viewer.getControl());
653 viewer.getControl().setMenu(menu);
654
655 // Register menu for extension.
656 getSite().registerContextMenu(menuMgr, viewer);
657 }
658
659 /**
660 * Fill context menu
661 *
662 * @param mgr Menu manager
663 */
664 protected void fillContextMenu(final IMenuManager mgr)
665 {
666 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
667 if (selection.isEmpty())
668 return;
669
670 if (selection.size() == 1)
671 {
672 if (((AgentFile)selection.getFirstElement()).isDirectory())
673 {
674 mgr.add(actionUploadFile);
675 }
676 else
677 {
678 mgr.add(actionTailFile);
679 mgr.add(actionShowFile);
680 }
681 }
682
683 mgr.add(actionDownloadFile);
684
685 if (isFolderOnlySelection(selection))
686 mgr.add(actionCalculateFolderSize);
687 mgr.add(new Separator());
688
689 if (selection.size() == 1)
690 {
691 if (((AgentFile)selection.getFirstElement()).isDirectory())
692 {
693 mgr.add(actionCreateDirectory);
694 }
695 mgr.add(actionRename);
696 }
697 mgr.add(actionDelete);
698 mgr.add(new Separator());
699 if (selection.size() == 1)
700 {
701 mgr.add(actionCopyFileName);
702 mgr.add(actionCopyFilePath);
703 }
704 mgr.add(new Separator());
705 mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
706 if ((selection.size() == 1) && ((AgentFile)selection.getFirstElement()).isDirectory())
707 {
708 mgr.add(new Separator());
709 mgr.add(actionRefreshDirectory);
710 }
711 }
712
713 /**
714 * Check if given selection contains only folders
715 *
716 * @param selection
717 * @return
718 */
719 private boolean isFolderOnlySelection(IStructuredSelection selection)
720 {
721 for(Object o : selection.toList())
722 if (!((AgentFile)o).isDirectory())
723 return false;
724 return true;
725 }
726
727 /**
728 * Refresh file list
729 */
730 private void refreshFileList()
731 {
732 new ConsoleJob(Messages.get().SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
733 @Override
734 protected void runInternal(IProgressMonitor monitor) throws Exception
735 {
736 final List<AgentFile> files = session.listAgentFiles(null, "/", objectId); //$NON-NLS-1$
737 runInUIThread(new Runnable() {
738 @Override
739 public void run()
740 {
741 viewer.setInput(files);
742 }
743 });
744 }
745
746 @Override
747 protected String getErrorMessage()
748 {
749 return Messages.get().SelectServerFileDialog_JobError;
750 }
751 }.start();
752 }
753
754 /**
755 * Refresh file list
756 */
757 private void refreshFileOrDirectory()
758 {
759 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
760 if (selection.isEmpty())
761 return;
762
763 final Object[] objects = selection.toArray();
764
765 new ConsoleJob("Reading remote directory", null, Activator.PLUGIN_ID, null) {
766 @Override
767 protected void runInternal(IProgressMonitor monitor) throws Exception
768 {
769 for(int i = 0; i < objects.length; i++)
770 {
771 if (!((AgentFile)objects[i]).isDirectory())
772 objects[i] = ((AgentFile)objects[i]).getParent();
773
774 final AgentFile sf = ((AgentFile)objects[i]);
775 sf.setChildren(session.listAgentFiles(sf, sf.getFullName(), objectId));
776
777 runInUIThread(new Runnable() {
778 @Override
779 public void run()
780 {
781 viewer.refresh(sf);
782 }
783 });
784 }
785 }
786
787 @Override
788 protected String getErrorMessage()
789 {
790 return "Cannot read remote directory";
791 }
792 }.start();
793 }
794
795 /**
796 * Upload local file to agent
797 */
798 private void uploadFile(final boolean overvrite)
799 {
800 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
801 if (selection.isEmpty())
802 return;
803
804 final Object[] objects = selection.toArray();
805 final AgentFile upladFolder = ((AgentFile)objects[0]).isDirectory() ? ((AgentFile)objects[0]) : ((AgentFile)objects[0])
806 .getParent();
807
808 final StartClientToServerFileUploadDialog dlg = new StartClientToServerFileUploadDialog(getSite().getShell());
809 if (dlg.open() == Window.OK)
810 {
811 final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
812 new ConsoleJob(Messages.get().AgentFileManager_UploadFileJobTitle, null, Activator.PLUGIN_ID, null) {
813 @Override
814 protected void runInternal(final IProgressMonitor monitor) throws Exception
815 {
816 List<File> fileList = dlg.getLocalFiles();
817 for(int i = 0; i < fileList.size(); i++)
818 {
819 final File localFile = fileList.get(i);
820 String remoteFile = fileList.get(i).getName();
821 if(fileList.size() == 1)
822 remoteFile = dlg.getRemoteFileName();
823 final String rFileName = remoteFile;
824
825 new NestedVerifyOverwrite(localFile.isDirectory() ? AgentFile.DIRECTORY : AgentFile.FILE, localFile.getName(), true, true, false) {
826
827 @Override
828 public void executeAction() throws NXCException, IOException
829 {
830 session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, overvrite, new ProgressListener() { //$NON-NLS-1$
831 private long prevWorkDone = 0;
832
833 @Override
834 public void setTotalWorkAmount(long workTotal)
835 {
836 monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
837 (int)workTotal);
838 }
839
840 @Override
841 public void markProgress(long workDone)
842 {
843 monitor.worked((int)(workDone - prevWorkDone));
844 prevWorkDone = workDone;
845 }
846 });
847 monitor.done();
848 }
849
850 @Override
851 public void executeSameFunctionWithOverwrite() throws IOException, NXCException
852 {
853 session.uploadLocalFileToAgent(objectId, localFile, upladFolder.getFullName()+"/"+rFileName, true, new ProgressListener() { //$NON-NLS-1$
854 private long prevWorkDone = 0;
855
856 @Override
857 public void setTotalWorkAmount(long workTotal)
858 {
859 monitor.beginTask(Messages.get(getDisplay()).UploadFileToServer_TaskNamePrefix + localFile.getAbsolutePath(),
860 (int)workTotal);
861 }
862
863 @Override
864 public void markProgress(long workDone)
865 {
866 monitor.worked((int)(workDone - prevWorkDone));
867 prevWorkDone = workDone;
868 }
869 });
870 monitor.done();
871 }
872 }.run(viewer.getControl().getDisplay());
873 }
874
875 upladFolder.setChildren(session.listAgentFiles(upladFolder, upladFolder.getFullName(), objectId));
876 runInUIThread(new Runnable() {
877 @Override
878 public void run()
879 {
880
881 viewer.refresh(upladFolder, true);
882 }
883 });
884 }
885
886 @Override
887 protected String getErrorMessage()
888 {
889 return "Cannot upload file to remote agent";
890 }
891 }.start();
892 }
893 }
894
895 /**
896 * Delete selected file
897 */
898 private void deleteFile()
899 {
900 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
901 if (selection.isEmpty())
902 return;
903
904 if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ViewServerFile_DeleteConfirmation,
905 Messages.get().ViewServerFile_DeletAck))
906 return;
907
908 final Object[] objects = selection.toArray();
909 new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
910 @Override
911 protected String getErrorMessage()
912 {
913 return Messages.get().ViewServerFile_ErrorDeleteFileJob;
914 }
915
916 @Override
917 protected void runInternal(IProgressMonitor monitor) throws Exception
918 {
919 for(int i = 0; i < objects.length; i++)
920 {
921 final AgentFile sf = (AgentFile)objects[i];
922 session.deleteAgentFile(objectId, sf.getFullName());
923
924 runInUIThread(new Runnable() {
925 @Override
926 public void run()
927 {
928 sf.getParent().removeChield(sf);
929 viewer.refresh(sf.getParent());
930 }
931 });
932 }
933 }
934 }.start();
935 }
936
937 /**
938 * Starts file tail
939 */
940 private void tailFile(final boolean followChanges, final int offset)
941 {
942 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
943 if (selection.isEmpty())
944 return;
945
946 final Object[] objects = selection.toArray();
947
948 if (((AgentFile)objects[0]).isDirectory())
949 return;
950
951 final AgentFile sf = ((AgentFile)objects[0]);
952
953 ConsoleJob job = new ConsoleJob(Messages.get().AgentFileManager_DownloadJobTitle, null, Activator.PLUGIN_ID, null) {
954 @Override
955 protected String getErrorMessage()
956 {
957 return String.format(Messages.get().AgentFileManager_DownloadJobError, sf.getFullName(), objectId);
958 }
959
960 @Override
961 protected void runInternal(final IProgressMonitor monitor) throws Exception
962 {
963 final AgentFileData file = session.downloadFileFromAgent(objectId, sf.getFullName(), offset, followChanges, new ProgressListener() {
964 @Override
965 public void setTotalWorkAmount(long workTotal)
966 {
967 monitor.beginTask("Download file " + sf.getFullName(), (int)workTotal);
968 }
969
970 @Override
971 public void markProgress(long workDone)
972 {
973 monitor.worked((int)workDone);
974 }
975 });
976 runInUIThread(new Runnable() {
977 @Override
978 public void run()
979 {
980 try
981 {
982 String secondaryId = Long.toString(objectId) + "&" + URLEncoder.encode(sf.getName(), "UTF-8"); //$NON-NLS-1$ //$NON-NLS-2$
983 AgentFileViewer.createView(secondaryId, objectId, file, followChanges);
984 }
985 catch(Exception e)
986 {
987 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
988 MessageDialogHelper.openError(window.getShell(), Messages.get().AgentFileManager_Error,
989 String.format(Messages.get().AgentFileManager_OpenViewError, e.getLocalizedMessage()));
990 Activator.logError("Exception in AgentFileManager.tailFile", e);
991 }
992 }
993 });
994 }
995 };
996 job.start();
997 }
998
999 /**
1000 * Download file from agent
1001 */
1002 private void startDownload()
1003 {
1004 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1005 if (selection.size() != 1)
1006 return;
1007
1008 final AgentFile sf = (AgentFile)selection.getFirstElement();
1009 if (!sf.isDirectory())
1010 {
1011 downloadFile(sf.getFullName());
1012 }
1013 else
1014 {
1015 ConsoleJob job = new ConsoleJob("Download from agent", null, Activator.PLUGIN_ID, null) {
1016 @Override
1017 protected void runInternal(final IProgressMonitor monitor) throws Exception
1018 {
1019 //create zip from download folder wile download
1020 long dirSize = -1;
1021 try
1022 {
1023 dirSize = session.getAgentFileInfo(sf).getSize();
1024 }
1025 catch(Exception e)
1026 {
1027 }
1028 monitor.beginTask(String.format("Downloading directory %s", sf.getName()), (int)dirSize);
1029
1030 final File zipFile = File.createTempFile("download_", ".zip");
1031 FileOutputStream fos = new FileOutputStream(zipFile);
1032 ZipOutputStream zos = new ZipOutputStream(fos);
1033 downloadDir(sf, sf.getName(), zos, monitor);
1034 zos.close();
1035 fos.close();
1036
1037 DownloadServiceHandler.addDownload(zipFile.getName(), sf.getName() + ".zip", zipFile, "application/octet-stream");
1038 runInUIThread(new Runnable() {
1039 @Override
1040 public void run()
1041 {
1042 DownloadServiceHandler.startDownload(zipFile.getName());
1043 }
1044 });
1045
1046 monitor.done();
1047 }
1048
1049 @Override
1050 protected String getErrorMessage()
1051 {
1052 return Messages.get().AgentFileManager_DirectoryReadError;
1053 }
1054 };
1055 job.start();
1056 }
1057 }
1058
1059 /**
1060 * Recursively download directory from agent to local pc
1061 *
1062 * @param sf
1063 * @param localFileName
1064 * @throws IOException
1065 * @throws NXCException
1066 */
1067 private void downloadDir(final AgentFile sf, String localFileName, ZipOutputStream zos, final IProgressMonitor monitor) throws NXCException, IOException
1068 {
1069 List<AgentFile> files = sf.getChildren();
1070 if (files == null)
1071 {
1072 files = session.listAgentFiles(sf, sf.getFullName(), sf.getNodeId());
1073 sf.setChildren(files);
1074 }
1075 for(AgentFile f : files)
1076 {
1077 if (f.isDirectory())
1078 {
1079 downloadDir(f, localFileName + "/" + f.getName(), zos, monitor);
1080 }
1081 else
1082 {
1083 monitor.subTask(String.format("Compressing file %s", f.getFullName()));
1084 final AgentFileData file = session.downloadFileFromAgent(objectId, f.getFullName(), 0, false, new ProgressListener() {
1085 @Override
1086 public void setTotalWorkAmount(long workTotal)
1087 {
1088 }
1089 @Override
1090 public void markProgress(long workDone)
1091 {
1092 monitor.worked((int)workDone);
1093 }
1094 });
1095
1096 FileInputStream fis = new FileInputStream(file.getFile());
1097 ZipEntry zipEntry = new ZipEntry(localFileName + "/" + f.getName());
1098 zos.putNextEntry(zipEntry);
1099 byte[] bytes = new byte[1024];
1100 int length;
1101 while ((length = fis.read(bytes)) >= 0)
1102 {
1103 zos.write(bytes, 0, length);
1104 }
1105 zos.closeEntry();
1106 fis.close();
1107 }
1108 }
1109 }
1110
1111 /**
1112 * Downloads file
1113 * @throws NXCException
1114 * @throws IOException
1115 */
1116 private void downloadFile(final String remoteName)
1117 {
1118 ConsoleJob job = new ConsoleJob(Messages.get().SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
1119 @Override
1120 protected void runInternal(final IProgressMonitor monitor) throws Exception
1121 {
1122 final AgentFileData file = session.downloadFileFromAgent(objectId, remoteName, 0, false, new ProgressListener() {
1123 @Override
1124 public void setTotalWorkAmount(long workTotal)
1125 {
1126 monitor.beginTask("Downloading file " + remoteName, (int)workTotal);
1127 }
1128
1129 @Override
1130 public void markProgress(long workDone)
1131 {
1132 monitor.worked((int)workDone);
1133 }
1134 });
1135
1136 DownloadServiceHandler.addDownload(file.getFile().getName(), remoteName, file.getFile(), "application/octet-stream");
1137 runInUIThread(new Runnable() {
1138 @Override
1139 public void run()
1140 {
1141 DownloadServiceHandler.startDownload(file.getFile().getName());
1142 }
1143 });
1144 }
1145
1146 @Override
1147 protected String getErrorMessage()
1148 {
1149 return Messages.get().AgentFileManager_DirectoryReadError;
1150 }
1151 };
1152 job.setUser(false);
1153 job.start();
1154 }
1155
1156 /**
1157 * Rename selected file
1158 */
1159 private void renameFile()
1160 {
1161 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1162 if (selection.size() != 1)
1163 return;
1164
1165 viewer.editElement(selection.getFirstElement(), 0);
1166 }
1167
1168 /**
1169 * Move selected file
1170 */
1171 private void moveFile(final AgentFile target, final AgentFile object)
1172 {
1173 new ConsoleJob(Messages.get().AgentFileManager_MoveFile, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
1174 @Override
1175 protected String getErrorMessage()
1176 {
1177 return Messages.get().AgentFileManager_MoveError;
1178 }
1179
1180 @Override
1181 protected void runInternal(IProgressMonitor monitor) throws Exception
1182 {
1183 NestedVerifyOverwrite verify = new NestedVerifyOverwrite(object.getType(), object.getName(), true, true, false) {
1184
1185 @Override
1186 public void executeAction() throws NXCException, IOException
1187 {
1188 session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), false); //$NON-NLS-1$
1189 }
1190
1191 @Override
1192 public void executeSameFunctionWithOverwrite() throws IOException, NXCException
1193 {
1194 session.renameAgentFile(objectId, object.getFullName(), target.getFullName() + "/" + object.getName(), true); //$NON-NLS-1$
1195 }
1196 };
1197 verify.run(viewer.getControl().getDisplay());
1198
1199 if(verify.isOkPressed())
1200 {
1201 runInUIThread(new Runnable() {
1202 @Override
1203 public void run()
1204 {
1205 object.getParent().removeChield(object);
1206 viewer.refresh(object.getParent(), true);
1207 object.setParent(target);
1208 target.addChield(object);
1209 viewer.refresh(object.getParent(), true);
1210 }
1211 });
1212 }
1213 }
1214 }.start();
1215 }
1216
1217 /**
1218 * Create new folder
1219 */
1220 private void createFolder()
1221 {
1222 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1223 if (selection.isEmpty())
1224 return;
1225
1226 final Object[] objects = selection.toArray();
1227 final AgentFile parentFolder = ((AgentFile)objects[0]).isDirectory() ? ((AgentFile)objects[0]) : ((AgentFile)objects[0])
1228 .getParent();
1229
1230 final CreateFolderDialog dlg = new CreateFolderDialog(getSite().getShell());
1231 if (dlg.open() != Window.OK)
1232 return;
1233
1234 final String newFolder = dlg.getNewName();
1235
1236 new ConsoleJob(Messages.get().AgentFileManager_CreatingFolder, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
1237 @Override
1238 protected String getErrorMessage()
1239 {
1240 return Messages.get().AgentFileManager_FolderCreationError;
1241 }
1242
1243 @Override
1244 protected void runInternal(IProgressMonitor monitor) throws Exception
1245 {
1246 NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {
1247
1248 @Override
1249 public void executeAction() throws NXCException, IOException
1250 {
1251 session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder); //$NON-NLS-1$
1252 }
1253
1254 @Override
1255 public void executeSameFunctionWithOverwrite() throws IOException, NXCException
1256 {
1257 //do nothing
1258 }
1259 };
1260 verify.run(viewer.getControl().getDisplay());
1261 parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
1262
1263 runInUIThread(new Runnable() {
1264 @Override
1265 public void run()
1266 {
1267 viewer.refresh(parentFolder, true);
1268 }
1269 });
1270 }
1271 }.start();
1272 }
1273
1274 /**
1275 * Show file size
1276 */
1277 private void calculateFolderSize()
1278 {
1279 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1280 if (selection.isEmpty())
1281 return;
1282
1283 final List<AgentFile> files = new ArrayList<AgentFile>(selection.size());
1284 for(Object o : selection.toList())
1285 files.add((AgentFile)o);
1286
1287 new ConsoleJob("Calculate folder size", this, Activator.PLUGIN_ID, null) {
1288 @Override
1289 protected void runInternal(IProgressMonitor monitor) throws Exception
1290 {
1291 for(AgentFile f : files)
1292 {
1293 f.setFileInfo(session.getAgentFileInfo(f));
1294 }
1295 runInUIThread(new Runnable() {
1296 @Override
1297 public void run()
1298 {
1299 viewer.update(files.toArray(), null);
1300 }
1301 });
1302 }
1303
1304 @Override
1305 protected String getErrorMessage()
1306 {
1307 return "Cannot calculate folder size";
1308 }
1309 }.start();
1310 }
1311
1312 /**
1313 * Copy name of file to clipboard
1314 */
1315 private void copyFileName()
1316 {
1317 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1318 if (selection.size() != 1)
1319 return;
1320
1321 WidgetHelper.copyToClipboard(((AgentFile)selection.getFirstElement()).getName());
1322 }
1323
1324 /**
1325 * Copy full path to file to clipboard
1326 */
1327 private void copyFilePath()
1328 {
1329 IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
1330 if (selection.size() != 1)
1331 return;
1332
1333 String filePath = ((AgentFile)selection.getFirstElement()).getFilePath();
1334 JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
1335 if( executor != null )
1336 {
1337 StringBuilder js = new StringBuilder();
1338 filePath = filePath.replace("\\", "\\\\");
1339 js.append("copyTextToClipboard(\'" + filePath + "\');"); // Substring is made to remove first "/"
1340 executor.execute(js.toString());
1341 }
1342 }
1343
1344 /*
1345 * (non-Javadoc)
1346 *
1347 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
1348 */
1349 @Override
1350 public void setFocus()
1351 {
1352 viewer.getControl().setFocus();
1353 }
1354
1355 /**
1356 * Enable or disable filter
1357 *
1358 * @param enable New filter state
1359 */
1360 private void enableFilter(boolean enable)
1361 {
1362 initShowFilter = enable;
1363 filterText.setVisible(initShowFilter);
1364 FormData fd = (FormData)viewer.getTree().getLayoutData();
1365 fd.top = enable ? new FormAttachment(filterText) : new FormAttachment(0, 0);
1366 content.layout();
1367 if (enable)
1368 {
1369 filterText.setFocus();
1370 }
1371 else
1372 {
1373 filterText.setText(""); //$NON-NLS-1$
1374 onFilterModify();
1375 }
1376 }
1377
1378 /**
1379 * Handler for filter modification
1380 */
1381 private void onFilterModify()
1382 {
1383 final String text = filterText.getText();
1384 filter.setFilterString(text);
1385 viewer.refresh(false);
1386 }
1387
1388 /**
1389 * Nested class that check if file already exist and it should be overwritten
1390 *
1391 */
1392 abstract class NestedVerifyOverwrite
1393 {
1394 private boolean okPresseed;
1395 private int type;
1396 private String name;
1397 private boolean askFolderOverwrite;
1398 private boolean askFileOverwrite;
1399 private boolean overwrite;
1400
1401 public NestedVerifyOverwrite(int fileType, String fileName, boolean askFolderOverwrite, boolean askFileOverwrite, boolean overwrite)
1402 {
1403 type = fileType;
1404 name = fileName;
1405 this.askFolderOverwrite = askFolderOverwrite;
1406 this.askFileOverwrite = askFileOverwrite;
1407 this.overwrite = overwrite;
1408 okPresseed = true;
1409 }
1410
1411 public boolean askFolderOverwrite()
1412 {
1413 return askFolderOverwrite;
1414 }
1415
1416 public boolean askFileOverwrite()
1417 {
1418 return askFileOverwrite;
1419 }
1420
1421 public void run(Display disp) throws IOException, NXCException
1422 {
1423 try
1424 {
1425 executeAction();
1426 }
1427 catch(final NXCException e)
1428 {
1429 if(e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST || type == AgentFile.DIRECTORY)
1430 {
1431 if(askFolderOverwrite)
1432 {
1433 disp.syncExec(new Runnable() {
1434 @Override
1435 public void run()
1436 {
1437 DialogData data = MessageDialogHelper.openOneButtonWarningWithCheckbox(getSite().getShell(),
1438 String.format("%s already exist", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File"),
1439 "Do not show again for this upload", String.format("%s %s already exist",e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
1440 askFolderOverwrite = !data.getSaveSelection();
1441 okPresseed = false;
1442 }
1443 });
1444 }
1445 }
1446 else if(e.getErrorCode() == RCC.FILE_ALREADY_EXISTS || e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST)
1447 {
1448 if(askFileOverwrite)
1449 {
1450 disp.syncExec(new Runnable() {
1451 @Override
1452 public void run()
1453 {
1454
1455 DialogData data = MessageDialogHelper.openWarningWithCheckbox(getSite().getShell(),
1456 String.format("%s overwrite confirmation", type == AgentFile.DIRECTORY ? "Folder" : "File"),
1457 "Save chose for current upload files",
1458 String.format("%s with %s name already exists. Are you sure you want to overwrite it?", e.getErrorCode() == RCC.FOLDER_ALREADY_EXIST ? "Folder" : "File", name));
1459 askFileOverwrite = !data.getSaveSelection();
1460 okPresseed = data.isOkPressed();
1461 }
1462 });
1463 if(okPresseed)
1464 executeSameFunctionWithOverwrite();
1465 }
1466 else
1467 {
1468 if(overwrite)
1469 {
1470 executeSameFunctionWithOverwrite();
1471 }
1472 }
1473 }
1474 else
1475 throw e;
1476 }
1477 }
1478 public boolean isOkPressed()
1479 {
1480 return okPresseed;
1481 }
1482 public abstract void executeAction() throws NXCException, IOException;
1483 public abstract void executeSameFunctionWithOverwrite() throws NXCException, IOException;
1484 }
1485 }