Search in sources :

Example 1 with LocalFileSelector

use of org.netxms.ui.eclipse.filemanager.widgets.LocalFileSelector in project netxms by netxms.

the class StartClientToServerFileUploadDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    fileSelector = new LocalFileSelector(dialogArea, SWT.NONE, false, SWT.OPEN | SWT.MULTI);
    fileSelector.setLabel(Messages.get().StartClientToServerFileUploadDialog_LocalFile);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = 400;
    fileSelector.setLayoutData(gd);
    fileSelector.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            localFiles = fileSelector.getFileList();
            if (localFiles.size() > 1) {
                textRemoteFile.setEditable(false);
            } else {
                textRemoteFile.setEditable(true);
            }
        }
    });
    textRemoteFile = new LabeledText(dialogArea, SWT.NONE);
    textRemoteFile.setLabel(Messages.get().StartClientToServerFileUploadDialog_RemoteFileName);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    textRemoteFile.setLayoutData(gd);
    return dialogArea;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) LocalFileSelector(org.netxms.ui.eclipse.filemanager.widgets.LocalFileSelector) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) GridData(org.eclipse.swt.layout.GridData)

Example 2 with LocalFileSelector

use of org.netxms.ui.eclipse.filemanager.widgets.LocalFileSelector in project netxms by netxms.

the class ImportDashboardDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    dialogArea.setLayout(layout);
    textName = new LabeledText(dialogArea, SWT.NONE);
    textName.setLabel(Messages.get().ImportDashboardDialog_ObjectName);
    textName.getTextControl().setTextLimit(63);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = 350;
    textName.setLayoutData(gd);
    importFileSelector = new LocalFileSelector(dialogArea, SWT.NONE, false, SWT.OPEN);
    importFileSelector.setLabel(Messages.get().ImportDashboardDialog_ImportFile);
    // $NON-NLS-1$ //$NON-NLS-2$
    importFileSelector.setFilterExtensions(new String[] { "*.xml", "*.*" });
    importFileSelector.setFilterNames(new String[] { Messages.get().ImportDashboardDialog_XMLFiles, Messages.get().ImportDashboardDialog_AllFiles });
    importFileSelector.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            Element root = null;
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document dom = db.parse(importFileSelector.getFile());
                root = dom.getDocumentElement();
                if (// $NON-NLS-1$
                !root.getNodeName().equals("dashboard"))
                    throw new Exception(Messages.get().ImportDashboard_InvalidFile);
                root.normalize();
            } catch (Exception e1) {
                MessageDialogHelper.openError(getShell(), "Error", "Unable to open the document");
            } finally {
                if (root == null)
                    return;
                NodeList nameRoot = root.getElementsByTagName("name");
                textName.setText(nameRoot.item(0).getTextContent());
                root.normalize();
            }
        }
    });
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = 350;
    importFileSelector.setLayoutData(gd);
    return dialogArea;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) LocalFileSelector(org.netxms.ui.eclipse.filemanager.widgets.LocalFileSelector) DocumentBuilder(javax.xml.parsers.DocumentBuilder) GridData(org.eclipse.swt.layout.GridData)

Aggregations

ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 LocalFileSelector (org.netxms.ui.eclipse.filemanager.widgets.LocalFileSelector)2 LabeledText (org.netxms.ui.eclipse.widgets.LabeledText)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1