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();
}
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);
}
}
}
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();
}
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();
}
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();
}
Aggregations