Search in sources :

Example 6 with AgentFile

use of org.netxms.client.server.AgentFile in project netxms by netxms.

the class AgentFileManager method createFolder.

/**
 * Create new folder
 */
private void createFolder() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    final Object[] objects = selection.toArray();
    final AgentFile parentFolder = ((AgentFile) objects[0]).isDirectory() ? ((AgentFile) objects[0]) : ((AgentFile) objects[0]).getParent();
    final CreateFolderDialog dlg = new CreateFolderDialog(getSite().getShell());
    if (dlg.open() != Window.OK)
        return;
    final String newFolder = dlg.getNewName();
    new ConsoleJob(Messages.get().AgentFileManager_CreatingFolder, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().AgentFileManager_FolderCreationError;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            NestedVerifyOverwrite verify = new NestedVerifyOverwrite(AgentFile.DIRECTORY, newFolder, true, true, false) {

                @Override
                public void executeAction() throws NXCException, IOException {
                    // $NON-NLS-1$
                    session.createFolderOnAgent(objectId, parentFolder.getFullName() + "/" + newFolder);
                }

                @Override
                public void executeSameFunctionWithOverwrite() throws IOException, NXCException {
                // do nothing
                }
            };
            verify.run(viewer.getControl().getDisplay());
            parentFolder.setChildren(session.listAgentFiles(parentFolder, parentFolder.getFullName(), objectId));
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.refresh(parentFolder, true);
                }
            });
        }
    }.start();
}
Also used : AgentFile(org.netxms.client.server.AgentFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) CreateFolderDialog(org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 7 with AgentFile

use of org.netxms.client.server.AgentFile in project netxms by netxms.

the class AgentFileComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    TreeColumn sortColumn = ((SortableTreeViewer) viewer).getTree().getSortColumn();
    if (sortColumn == null)
        return 0;
    int rc;
    switch(// $NON-NLS-1$
    (Integer) sortColumn.getData("ID")) {
        case AgentFileManager.COLUMN_NAME:
            if (((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory()) {
                rc = ((AgentFile) e1).getName().compareToIgnoreCase(((AgentFile) e2).getName());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_TYPE:
            if (((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory()) {
                rc = ((AgentFile) e1).getExtension().compareToIgnoreCase(((AgentFile) e2).getExtension());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_SIZE:
            if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
                rc = Long.signum(((AgentFile) e1).getSize() - ((AgentFile) e2).getSize());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_MODIFYED:
            if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
                rc = ((AgentFile) e1).getModifyicationTime().compareTo(((AgentFile) e2).getModifyicationTime());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_OWNER:
            if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
                rc = ((AgentFile) e1).getOwner().compareTo(((AgentFile) e2).getOwner());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_GROUP:
            if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
                rc = ((AgentFile) e1).getGroup().compareTo(((AgentFile) e2).getGroup());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        case AgentFileManager.COLUMN_ACCESS_RIGHTS:
            if ((((AgentFile) e1).isDirectory() == ((AgentFile) e2).isDirectory())) {
                rc = ((AgentFile) e1).getAccessRights().compareTo(((AgentFile) e2).getAccessRights());
            } else {
                rc = ((AgentFile) e1).isDirectory() ? -1 : 1;
            }
            break;
        default:
            rc = 0;
            break;
    }
    int dir = ((SortableTreeViewer) viewer).getTree().getSortDirection();
    return (dir == SWT.UP) ? rc : -rc;
}
Also used : TreeColumn(org.eclipse.swt.widgets.TreeColumn) AgentFile(org.netxms.client.server.AgentFile)

Example 8 with AgentFile

use of org.netxms.client.server.AgentFile in project netxms by netxms.

the class AgentFileFilter method select.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if ((filterString == null) || (filterString.isEmpty()))
        return true;
    final AgentFile filename = (AgentFile) element;
    boolean pass = filename.getName().toLowerCase().contains(filterString.toLowerCase());
    List<AgentFile> children = filename.getChildren();
    if (!pass && children != null) {
        pass = containString(children);
    }
    return pass;
}
Also used : AgentFile(org.netxms.client.server.AgentFile)

Example 9 with AgentFile

use of org.netxms.client.server.AgentFile in project netxms by netxms.

the class ViewAgentFilesProvider method getChildren.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
	 */
@Override
public Object[] getChildren(final Object parentElement) {
    if (((AgentFile) parentElement).getChildren() == null) {
        ConsoleJob job = new ConsoleJob(Messages.get().ViewAgentFilesProvider_JobTitle, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final List<AgentFile> files = session.listAgentFiles(((AgentFile) parentElement), ((AgentFile) parentElement).getFullName(), ((AgentFile) parentElement).getNodeId());
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        ((AgentFile) parentElement).setChildren(files);
                        ((StructuredViewer) viewer).refresh(parentElement);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().ViewAgentFilesProvider_JobError;
            }
        };
        job.setUser(false);
        job.start();
        return new AgentFile[] { new AgentFile(Messages.get().ViewAgentFilesProvider_Loading, AgentFile.PLACEHOLDER, (AgentFile) parentElement, ((AgentFile) parentElement).getNodeId()) };
    }
    return ((AgentFile) parentElement).getChildren().toArray();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AgentFile(org.netxms.client.server.AgentFile) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 10 with AgentFile

use of org.netxms.client.server.AgentFile in project netxms by netxms.

the class NXCSession method listAgentFiles.

/**
 * List files on agent file store.
 *
 * @param file parent of new coomming list
 * @param fullPath path that will be used on an agent to get list of subfiles
 * @param objectId the ID of the node
 * @return will return the list of sub files or the list of allowed folders if full path is set to "/"
 * @throws IOException if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<AgentFile> listAgentFiles(AgentFile file, String fullPath, long objectId) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_FOLDER_CONTENT);
    msg.setField(NXCPCodes.VID_FILE_NAME, fullPath);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) objectId);
    msg.setFieldInt16(NXCPCodes.VID_ROOT, file == null ? 1 : 0);
    msg.setFieldInt16(NXCPCodes.VID_ALLOW_MULTIPART, 1);
    sendMessage(msg);
    List<AgentFile> files = new ArrayList<AgentFile>(64);
    while (true) {
        final NXCPMessage response = waitForRCC(msg.getMessageId());
        int count = response.getFieldAsInt32(NXCPCodes.VID_INSTANCE_COUNT);
        long fieldId = NXCPCodes.VID_INSTANCE_LIST_BASE;
        for (int i = 0; i < count; i++) {
            files.add(new AgentFile(response, fieldId, file, objectId));
            fieldId += 10;
        }
        if (!response.getFieldAsBoolean(NXCPCodes.VID_ALLOW_MULTIPART))
            // old version of server or agent without multipart support
            return files;
        if (response.isEndOfSequence())
            break;
    }
    waitForRCC(msg.getMessageId());
    return files;
}
Also used : AgentFile(org.netxms.client.server.AgentFile) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Aggregations

AgentFile (org.netxms.client.server.AgentFile)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 IOException (java.io.IOException)7 PartInitException (org.eclipse.ui.PartInitException)7 NXCException (org.netxms.client.NXCException)7 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)7 File (java.io.File)4 ArrayList (java.util.ArrayList)3 AgentFileData (org.netxms.client.AgentFileData)3 ProgressListener (org.netxms.client.ProgressListener)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 ConsoleJobCallingServerJob (org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 GroupMarker (org.eclipse.jface.action.GroupMarker)1