Search in sources :

Example 1 with ServerFile

use of org.netxms.client.server.ServerFile in project netxms by netxms.

the class AlarmSounds method createContents.

/*
    * (non-Javadoc)
    * 
    * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    Combo newCombo = null;
    Button button = null;
    for (int i = 0; i < 6; i++) {
        final String soundId = (i < 5) ? StatusDisplayInfo.getStatusText(i) : "Outstanding alarm reminder";
        newCombo = WidgetHelper.createLabeledCombo(dialogArea, SWT.DROP_DOWN | SWT.READ_ONLY, soundId, WidgetHelper.DEFAULT_LAYOUT_DATA);
        newCombo.setEnabled(false);
        comboList.add(i, newCombo);
        button = new Button(dialogArea, SWT.PUSH);
        GridData gridData = new GridData();
        gridData.verticalAlignment = GridData.END;
        button.setLayoutData(gridData);
        // $NON-NLS-1$
        button.setImage(Activator.getImageDescriptor("icons/sound.png").createImage());
        final int index = i;
        button.addMouseListener(new MouseListener() {

            @Override
            public void mouseUp(MouseEvent e) {
                String fileName = comboList.get(index).getText();
                getMelodyAndDownloadIfRequired(fileName);
                JavaScriptExecutor executor = RWT.getClient().getService(JavaScriptExecutor.class);
                File localFile = new File(workspaceUrl.getPath(), fileName);
                String id = "audio-" + fileName;
                // $NON-NLS-1$
                DownloadServiceHandler.addDownload(id, fileName, localFile, "audio/wav");
                StringBuilder js = new StringBuilder();
                js.append("var testAudio = document.createElement('audio');");
                js.append("if (testAudio.canPlayType !== undefined)");
                js.append("{");
                // $NON-NLS-1$
                js.append("var audio = new Audio('");
                js.append(DownloadServiceHandler.createDownloadUrl(id));
                // $NON-NLS-1$
                js.append("');");
                // $NON-NLS-1$
                js.append("audio.play();");
                js.append("}");
                executor.execute(js.toString());
            }

            @Override
            public void mouseDown(MouseEvent e) {
            // do noting
            }

            @Override
            public void mouseDoubleClick(MouseEvent e) {
            // do noting
            }
        });
        buttonList.add(i, button);
    }
    new UIJob(Messages.get().AlarmMelody_JobGetMelodyList) {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            try {
                // $NON-NLS-1$
                String[] s = { "wav" };
                serverFiles = session.listServerFiles(s);
            } catch (final Exception e) {
                e.printStackTrace();
                getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialogHelper.openError(getShell(), Messages.get().AlarmMelody_ErrorGettingMelodyList, Messages.get().AlarmMelody_ErrorGettingMelodyListDescription + e.getMessage());
                    }
                });
            }
            for (ServerFile s : serverFiles) {
                soundList.add(s.getName());
            }
            // $NON-NLS-1$
            soundList.add("");
            for (int i = 0; i < 6; i++) {
                // $NON-NLS-1$
                currentSoundList.add(i, ps.getString("ALARM_NOTIFIER.MELODY." + AlarmNotifier.SEVERITY_TEXT[i]));
            }
            soundList.addAll(currentSoundList);
            Combo newCombo = null;
            for (int i = 0; i < 6; i++) {
                newCombo = comboList.get(i);
                newCombo.setEnabled(true);
                newCombo.setItems(soundList.toArray(new String[soundList.size()]));
                newCombo.select(newCombo.indexOf(currentSoundList.get(i)));
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return dialogArea;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) JavaScriptExecutor(org.eclipse.rap.rwt.client.service.JavaScriptExecutor) ServerFile(org.netxms.client.server.ServerFile) Combo(org.eclipse.swt.widgets.Combo) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) ServerFile(org.netxms.client.server.ServerFile) File(java.io.File)

Example 2 with ServerFile

use of org.netxms.client.server.ServerFile in project netxms by netxms.

the class AlarmSounds method downloadSoundFile.

/**
 * Download sound file from server
 *
 * @param session
 * @param melodyName
 * @param workspaceUrl
 * @throws NXCException
 * @throws IOException
 */
@SuppressWarnings("resource")
private static void downloadSoundFile(NXCSession session, String melodyName, URL workspaceUrl) throws NXCException, IOException {
    File serverFile = session.downloadFileFromServer(melodyName);
    FileChannel src = null;
    FileChannel dest = null;
    try {
        src = new FileInputStream(serverFile).getChannel();
        File f = new File(workspaceUrl.getPath(), melodyName);
        f.createNewFile();
        dest = new FileOutputStream(f).getChannel();
        dest.transferFrom(src, 0, src.size());
    } catch (IOException e) {
        // $NON-NLS-1$
        Activator.logError("Cannot copy sound file", e);
    } finally {
        if (src != null)
            src.close();
        if (dest != null)
            dest.close();
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ServerFile(org.netxms.client.server.ServerFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with ServerFile

use of org.netxms.client.server.ServerFile in project netxms by netxms.

the class UploadFileToAgent method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    boolean canScheduleFileUpload = (session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_SCHEDULE_FILE_UPLOAD) > 0;
    final StartServerToAgentFileUploadDialog dlg = new StartServerToAgentFileUploadDialog(shell, canScheduleFileUpload);
    if (dlg.open() == Window.OK) {
        final Long[] nodeIdList = nodes.toArray(new Long[nodes.size()]);
        new ConsoleJob(Messages.get().UploadFileToAgent_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

            @Override
            protected String getErrorMessage() {
                return Messages.get().UploadFileToAgent_JobError;
            }

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                boolean multipleFiles = dlg.getServerFiles().size() > 1;
                for (ServerFile sf : dlg.getServerFiles()) {
                    String remoteFileName = dlg.getRemoteFileName();
                    if (!remoteFileName.isEmpty()) {
                        if (// $NON-NLS-1$ //$NON-NLS-2$
                        remoteFileName.endsWith("/") || remoteFileName.endsWith("\\")) {
                            remoteFileName += sf.getName();
                        } else if (multipleFiles) {
                            remoteFileName += "/" + sf.getName();
                        }
                    } else {
                        if (!dlg.isScheduled())
                            remoteFileName = null;
                    }
                    for (int i = 0; i < nodeIdList.length; i++) {
                        if (dlg.isScheduled()) {
                            ScheduledTask task = dlg.getScheduledTask();
                            // $NON-NLS-1$
                            String parameters = sf.getName() + "," + remoteFileName;
                            task.setParameters(parameters);
                            task.setObjectId(nodeIdList[i]);
                            session.addSchedule(task);
                        } else {
                            session.uploadFileToAgent(nodeIdList[i], sf.getName(), remoteFileName, dlg.isCreateJobOnHold());
                        }
                    }
                }
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) StartServerToAgentFileUploadDialog(org.netxms.ui.eclipse.filemanager.dialogs.StartServerToAgentFileUploadDialog) ServerFile(org.netxms.client.server.ServerFile) ScheduledTask(org.netxms.client.ScheduledTask) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 4 with ServerFile

use of org.netxms.client.server.ServerFile in project netxms by netxms.

the class ServerFileManager method deleteFile.

/**
 * Delete selected file
 */
private void deleteFile() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.isEmpty())
        return;
    if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ViewServerFile_DeleteConfirmation, Messages.get().ViewServerFile_DeletAck))
        return;
    final Object[] objects = selection.toArray();
    new ConsoleJob(Messages.get().ViewServerFile_DeletFileFromServerJob, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().ViewServerFile_ErrorDeleteFileJob;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (int i = 0; i < objects.length; i++) {
                session.deleteServerFile(((ServerFile) objects[i]).getName());
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ServerFile(org.netxms.client.server.ServerFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with ServerFile

use of org.netxms.client.server.ServerFile in project netxms by netxms.

the class StartServerToAgentFileUploadDialog 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);
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(Messages.get().StartServerToAgentFileUploadDialog_ServerFile);
    fileList = new TableViewer(dialogArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = 400;
    gd.heightHint = 150;
    fileList.getControl().setLayoutData(gd);
    fileList.setContentProvider(new ArrayContentProvider());
    fileList.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ServerFile) element).getName();
        }
    });
    fileList.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((ServerFile) e1).getName().compareToIgnoreCase(((ServerFile) e2).getName());
        }
    });
    fileList.setInput(serverFiles);
    Composite buttonArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    buttonArea.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttonArea.setLayoutData(gd);
    buttonAddFile = new Button(buttonArea, SWT.PUSH);
    buttonAddFile.setText("&Add...");
    gd = new GridData();
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAddFile.setLayoutData(gd);
    buttonAddFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectServerFileDialog dlg = new SelectServerFileDialog(getShell(), true);
            if (dlg.open() == Window.OK) {
                for (ServerFile f : dlg.getSelectedFiles()) {
                    boolean found = false;
                    for (ServerFile sf : serverFiles) if (sf.getName().equals(f.getName())) {
                        found = true;
                        break;
                    }
                    if (!found)
                        serverFiles.add(f);
                }
                fileList.refresh();
            }
        }
    });
    buttonRemoveFile = new Button(buttonArea, SWT.PUSH);
    buttonRemoveFile.setText("&Remove");
    gd = new GridData();
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemoveFile.setLayoutData(gd);
    buttonRemoveFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fileList.getSelection();
            for (Object o : selection.toList()) serverFiles.remove(o);
            fileList.refresh();
        }
    });
    textRemoteFile = new LabeledText(dialogArea, SWT.NONE);
    textRemoteFile.setLabel(Messages.get().StartServerToAgentFileUploadDialog_RemoteFileName);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    textRemoteFile.setLayoutData(gd);
    checkJobOnHold = new Button(dialogArea, SWT.CHECK);
    checkJobOnHold.setText(Messages.get().StartServerToAgentFileUploadDialog_CreateJobOnHold);
    checkJobOnHold.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkIsSchedule.setEnabled(!checkJobOnHold.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    if (canScheduleFileUpload) {
        checkIsSchedule = new Button(dialogArea, SWT.CHECK);
        checkIsSchedule.setText(Messages.get().StartServerToAgentFileUploadDialog_ScheduleTask);
        checkIsSchedule.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                checkJobOnHold.setEnabled(!checkIsSchedule.getSelection());
                scheduleSelector.setEnabled(checkIsSchedule.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        scheduleSelector = new ScheduleSelector(dialogArea, SWT.NONE);
        scheduleSelector.setEnabled(false);
    }
    return dialogArea;
}
Also used : ScheduleSelector(org.netxms.ui.eclipse.widgets.ScheduleSelector) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ServerFile(org.netxms.client.server.ServerFile) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ServerFile (org.netxms.client.server.ServerFile)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 File (java.io.File)2 IOException (java.io.IOException)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FileChannel (java.nio.channels.FileChannel)1 IStatus (org.eclipse.core.runtime.IStatus)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1