Search in sources :

Example 1 with CreateFolderDialog

use of org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog 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)

Aggregations

IOException (java.io.IOException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 PartInitException (org.eclipse.ui.PartInitException)1 NXCException (org.netxms.client.NXCException)1 AgentFile (org.netxms.client.server.AgentFile)1 CreateFolderDialog (org.netxms.ui.eclipse.filemanager.dialogs.CreateFolderDialog)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1