Search in sources :

Example 1 with PathElement

use of org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement in project netxms by netxms.

the class FileDeliveryPolicyEditor method deleteElements.

/**
 * Delete selected elements
 */
private void deleteElements() {
    IStructuredSelection selection = fileTree.getStructuredSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openQuestion(getShell(), "Delete confirmation", "Delete selected files?"))
        return;
    for (Object o : selection.toList()) {
        PathElement element = (PathElement) o;
        if (element.isFile())
            deleteFiles(element);
        if (element.getParent() == null) {
            rootElements.remove(o);
        } else {
            element.remove();
        }
    }
    fileTree.refresh(true);
    fireModifyListeners();
}
Also used : PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with PathElement

use of org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement in project netxms by netxms.

the class FileDeliveryPolicyEditor method checkForMissingElements.

/**
 * Check for missing elements
 *
 * @param newElements new element set
 * @param originalElements original element set
 * @param createMissing true if missing elements should be created
 */
private void checkForMissingElements(Set<PathElement> newElements, Set<PathElement> originalElements, boolean createMissing) {
    Iterator<PathElement> iter = newElements.iterator();
    while (iter.hasNext()) {
        PathElement newElement = iter.next();
        PathElement originalElement = null;
        for (PathElement e : originalElements) {
            if (newElement.getName().equals(e.getName())) {
                originalElement = e;
                break;
            }
        }
        if (originalElement == null) {
            if (createMissing) {
                fileTree.refresh(newElement, true);
                originalElements.add(newElement);
            } else {
                iter.remove();
            }
        } else if (newElement.isFile() != originalElement.isFile() && createMissing) {
            originalElements.add(newElement);
        } else if (!newElement.isFile()) {
            checkForMissingElements(newElement.getChildrenSet(), originalElement.getChildrenSet(), createMissing);
        }
    }
}
Also used : PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement)

Example 3 with PathElement

use of org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement in project netxms by netxms.

the class FileDeliveryPolicyEditor method updatePolicyFromControl.

/**
 * @see org.netxms.ui.eclipse.datacollection.widgets.AbstractPolicyEditor#updatePolicyFromControl()
 */
@Override
public AgentPolicy updatePolicyFromControl() {
    FileDeliveryPolicy data = new FileDeliveryPolicy();
    data.elements = rootElements.toArray(new PathElement[rootElements.size()]);
    try {
        getPolicy().setContent(data.createXml());
    } catch (Exception e) {
        Activator.logError("Error serializing file delivery policy", e);
    }
    return getPolicy();
}
Also used : PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) FileDeliveryPolicy(org.netxms.ui.eclipse.datacollection.widgets.helpers.FileDeliveryPolicy)

Example 4 with PathElement

use of org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement in project netxms by netxms.

the class FileDeliveryPolicyEditor method updateFile.

/**
 * Update file content
 */
private void updateFile() {
    IStructuredSelection selection = fileTree.getStructuredSelection();
    if ((selection.size() != 1) || !((PathElement) selection.getFirstElement()).isFile())
        return;
    FileDialog dlg = new FileDialog(getShell(), SWT.OPEN);
    String fileName = dlg.open();
    if (fileName == null)
        return;
    final File file = new File(fileName);
    if (!file.exists())
        return;
    final UUID guid = ((PathElement) selection.getFirstElement()).getGuid();
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Upload file", getViewPart(), Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(final IProgressMonitor monitor) throws Exception {
            session.uploadFileToServer(file, "FileDelivery-" + guid.toString(), new ProgressListener() {

                @Override
                public void setTotalWorkAmount(long workTotal) {
                    monitor.beginTask("Upload file", (int) file.length());
                }

                @Override
                public void markProgress(long workDone) {
                    monitor.worked((int) workDone);
                }
            });
            monitor.done();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    ((PathElement) selection.getFirstElement()).updateCreationTime();
                    fileTree.refresh(true);
                    fireModifyListeners();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot upload file";
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) ProgressListener(org.netxms.client.ProgressListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) UUID(java.util.UUID) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 5 with PathElement

use of org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement in project netxms by netxms.

the class FileDeliveryPolicyEditor method changePermissions.

/**
 * Change file permissions
 */
private void changePermissions() {
    IStructuredSelection selection = fileTree.getStructuredSelection();
    if (selection.size() != 1)
        return;
    PathElement element = (PathElement) selection.getFirstElement();
    FilePermissionDialog dlg = new FilePermissionDialog(getShell(), element.getPermissions(), element.getOwner(), element.getOwnerGroup());
    if (dlg.open() != Window.OK)
        return;
    element.setPermissions(dlg.getPermissions());
    element.setOwner(dlg.getOwner());
    element.setOwnerGroup(dlg.getGroup());
    fileTree.update(element, null);
    fireModifyListeners();
}
Also used : PathElement(org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FilePermissionDialog(org.netxms.ui.eclipse.datacollection.dialogs.FilePermissionDialog)

Aggregations

PathElement (org.netxms.ui.eclipse.datacollection.widgets.helpers.PathElement)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 File (java.io.File)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 FileDialog (org.eclipse.swt.widgets.FileDialog)2 NXCSession (org.netxms.client.NXCSession)2 FileDeliveryPolicy (org.netxms.ui.eclipse.datacollection.widgets.helpers.FileDeliveryPolicy)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 ProgressListener (org.netxms.client.ProgressListener)1 FilePermissionDialog (org.netxms.ui.eclipse.datacollection.dialogs.FilePermissionDialog)1