use of org.netxms.ui.eclipse.dashboard.dialogs.ImportDashboardDialog in project netxms by netxms.
the class ImportDashboard method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
final ImportDashboardDialog dlg = new ImportDashboardDialog(window.getShell());
if (dlg.open() != Window.OK)
return;
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final Display display = Display.getCurrent();
new ConsoleJob(Messages.get().ImportDashboard_JobTitle, part, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(dlg.getImportFile());
Element root = dom.getDocumentElement();
if (// $NON-NLS-1$
!root.getNodeName().equals("dashboard"))
throw new Exception(Messages.get().ImportDashboard_InvalidFile);
root.normalize();
List<DashboardElement> dashboardElements = new ArrayList<DashboardElement>();
// $NON-NLS-1$
NodeList elementsRoot = root.getElementsByTagName("elements");
for (int i = 0; i < elementsRoot.getLength(); i++) {
if (elementsRoot.item(i).getNodeType() != Node.ELEMENT_NODE)
continue;
// $NON-NLS-1$
NodeList elements = ((Element) elementsRoot.item(i)).getElementsByTagName("dashboardElement");
for (int j = 0; j < elements.getLength(); j++) {
Element e = (Element) elements.item(j);
// $NON-NLS-1$ //$NON-NLS-2$
DashboardElement de = new DashboardElement(getNodeValueAsInt(e, "type", 0), getNodeValueAsXml(e, "element"));
// $NON-NLS-1$
de.setLayout(getNodeValueAsXml(e, "layout"));
dashboardElements.add(de);
}
}
root.normalize();
objectName = dlg.getObjectName();
if (doIdMapping(display, session, dashboardElements, root)) {
NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_DASHBOARD, objectName, parentId);
final long objectId = session.createObject(cd);
NXCObjectModificationData md = new NXCObjectModificationData(objectId);
// $NON-NLS-1$
md.setColumnCount(getNodeValueAsInt(root, "columns", 1));
// $NON-NLS-1$
md.setObjectFlags(getNodeValueAsInt(root, "options", 0));
md.setDashboardElements(dashboardElements);
session.modifyObject(md);
}
}
@Override
protected String getErrorMessage() {
return String.format(Messages.get().ImportDashboard_Error, dlg.getObjectName());
}
}.start();
}
Aggregations