Search in sources :

Example 46 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class EmbeddedDashboard method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    config = (EmbeddedDashboardConfig) getElement().getAdapter(EmbeddedDashboardConfig.class);
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(Messages.get().EmbeddedDashboard_Dashboards);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 0;
    viewer.getTable().setLayoutData(gd);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    dashboardObjects = session.findMultipleObjects(config.getDashboardObjects(), Dashboard.class, false);
    viewer.setInput(dashboardObjects.toArray());
    /* buttons on left side */
    Composite leftButtons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginLeft = 0;
    leftButtons.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gd);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().EmbeddedDashboard_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    upButton.setEnabled(false);
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().EmbeddedDashboard_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    downButton.setEnabled(false);
    /* buttons on right side */
    Composite rightButtons = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    rightButtons.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    rightButtons.setLayoutData(gd);
    addButton = new Button(rightButtons, SWT.PUSH);
    addButton.setText(Messages.get().EmbeddedDashboard_Add);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addDashboard();
        }
    });
    deleteButton = new Button(rightButtons, SWT.PUSH);
    deleteButton.setText(Messages.get().EmbeddedDashboard_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteDashboards();
        }
    });
    deleteButton.setEnabled(false);
    Composite refreshIntervalGroup = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.marginTop = WidgetHelper.OUTER_SPACING;
    refreshIntervalGroup.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    refreshIntervalGroup.setLayoutData(gd);
    label = new Label(refreshIntervalGroup, SWT.NONE);
    label.setText(Messages.get().EmbeddedDashboard_DisplayTime);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    refreshIntervalScale = new Scale(refreshIntervalGroup, SWT.HORIZONTAL);
    refreshIntervalScale.setMinimum(1);
    refreshIntervalScale.setMaximum(600);
    refreshIntervalScale.setSelection(config.getDisplayInterval());
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    refreshIntervalScale.setLayoutData(gd);
    refreshIntervalScale.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshIntervalSpinner.setSelection(refreshIntervalScale.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    refreshIntervalSpinner = new Spinner(refreshIntervalGroup, SWT.BORDER);
    refreshIntervalSpinner.setMinimum(1);
    refreshIntervalSpinner.setMaximum(600);
    refreshIntervalSpinner.setSelection(config.getDisplayInterval());
    refreshIntervalSpinner.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshIntervalScale.setSelection(refreshIntervalSpinner.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            deleteButton.setEnabled(selection.size() > 0);
            upButton.setEnabled(selection.size() == 1);
            downButton.setEnabled(selection.size() == 1);
        }
    });
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) Spinner(org.eclipse.swt.widgets.Spinner) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) Dashboard(org.netxms.client.objects.Dashboard) Scale(org.eclipse.swt.widgets.Scale) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 47 with NXCSession

use of org.netxms.client.NXCSession 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 48 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class MapBackground method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    if (radioTypeNone.getSelection()) {
        md.setMapBackground(NXCommon.EMPTY_GUID, new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    } else if (radioTypeImage.getSelection()) {
        md.setMapBackground(image.getImageGuid(), new GeoLocation(false), 0, ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    } else if (!disableGeolocationBackground && radioTypeGeoMap.getSelection()) {
        GeoLocation location;
        try {
            location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        } catch (GeoLocationFormatException e) {
            MessageDialogHelper.openError(getShell(), Messages.get().MapBackground_Error, Messages.get().MapBackground_GeoLocFormatError);
            return false;
        }
        md.setMapBackground(NetworkMap.GEOMAP_BACKGROUND, location, zoomSpinner.getSelection(), ColorConverter.rgbToInt(backgroundColor.getColorValue()));
    }
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().MapBackground_JobTitle + object.getObjectName(), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MapBackground_JobError + object.getObjectName();
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        MapBackground.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException)

Example 49 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class MapObjectFilter method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    final String filter = filterSource.getText();
    if (initialFilter.equals(filter) && (checkboxEnableFilter.getSelection() == initialEnable))
        // Nothing to apply
        return;
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setFilter(filter);
    md.setObjectFlags(checkboxEnableFilter.getSelection() ? NetworkMap.MF_FILTER_OBJECTS : 0, NetworkMap.MF_FILTER_OBJECTS);
    new ConsoleJob(Messages.get().MapObjectFilter_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        initialFilter = filter;
                        initialEnable = checkboxEnableFilter.getSelection();
                        MapObjectFilter.this.setValid(true);
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MapObjectFilter_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 50 with NXCSession

use of org.netxms.client.NXCSession in project netxms by netxms.

the class SelectScriptDialog 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);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().SelectScriptDialog_AvailableScripts);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | (multiSelection ? SWT.MULTI : 0));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

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

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Script s1 = (Script) e1;
            Script s2 = (Script) e2;
            return s1.getName().compareToIgnoreCase(s2.getName());
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            SelectScriptDialog.this.okPressed();
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    gd.widthHint = 400;
    viewer.getControl().setLayoutData(gd);
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SelectScriptDialog_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<Script> scripts = session.getScriptLibrary();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(scripts.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectScriptDialog_JobError;
        }
    }.start();
    return dialogArea;
}
Also used : Script(org.netxms.client.Script) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10