12cb56ee44432e1598427d853132947463ad10fe
[public/netxms.git] / webui / webapp / FileManager / src / org / netxms / ui / eclipse / filemanager / views / helpers / ViewAgentFilesProvider.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2012 Victor Kirhenshtein
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.helpers;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.eclipse.core.runtime.IProgressMonitor;
24 import org.eclipse.jface.viewers.ITreeContentProvider;
25 import org.eclipse.jface.viewers.StructuredViewer;
26 import org.eclipse.jface.viewers.Viewer;
27 import org.netxms.client.NXCSession;
28 import org.netxms.client.ServerFile;
29 import org.netxms.ui.eclipse.filemanager.Activator;
30 import org.netxms.ui.eclipse.filemanager.Messages;
31 import org.netxms.ui.eclipse.jobs.ConsoleJob;
32 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
33
34 /**
35 * Content provider for event tree
36 */
37 public class ViewAgentFilesProvider implements ITreeContentProvider
38 {
39 private Viewer viewer;
40 private NXCSession session = (NXCSession)ConsoleSharedData.getSession();
41
42 /* (non-Javadoc)
43 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
44 */
45 @Override
46 public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
47 {
48 this.viewer = viewer;
49 }
50
51 /* (non-Javadoc)
52 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
53 */
54 @Override
55 public Object[] getChildren(final Object parentElement)
56 {
57 if(((ServerFile)parentElement).getChildren() == null)
58 {
59 ConsoleJob job = new ConsoleJob(Messages.get().SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
60 @Override
61 protected void runInternal(IProgressMonitor monitor) throws Exception
62 {
63 final ServerFile[] files = session.listAgentFiles(((ServerFile)parentElement), ((ServerFile)parentElement).getFullName(), ((ServerFile)parentElement).getNodeId());
64 runInUIThread(new Runnable() {
65 @Override
66 public void run()
67 {
68 ((ServerFile)parentElement).setChildren(files);
69 ((StructuredViewer)viewer).refresh(parentElement);
70 }
71 });
72 }
73
74 @Override
75 protected String getErrorMessage()
76 {
77 return "Error while retrieving children of server file";
78 }
79 };
80 job.setUser(false);
81 job.start();
82 return new ServerFile[] { new ServerFile("Loading...", ServerFile.PLACEHOLDER, (ServerFile)parentElement, ((ServerFile)parentElement).getNodeId()) };
83 }
84 return ((ServerFile)parentElement).getChildren();
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
89 */
90 @Override
91 public Object getParent(Object element)
92 {
93 return ((ServerFile)element).getParent();
94 }
95
96 /* (non-Javadoc)
97 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
98 */
99 @Override
100 public boolean hasChildren(Object element)
101 {
102 return ((ServerFile)element).isDirectory();
103 }
104
105 /* (non-Javadoc)
106 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
107 */
108 @Override
109 public void dispose()
110 {
111 }
112
113 /* (non-Javadoc)
114 * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
115 */
116 @Override
117 public Object[] getElements(Object inputElement)
118 {
119 List<ServerFile> list = new ArrayList<ServerFile>();
120 for(ServerFile e : (ServerFile[])inputElement)
121 if (e.getParent() == null)
122 list.add(e);
123 return list.toArray();
124 }
125
126
127
128 }