Search in sources :

Example 66 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class UserManagementView method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = ConsoleSharedData.getSession();
    final String[] names = { Messages.get().UserManagementView_Name, Messages.get().UserManagementView_Type, Messages.get().UserManagementView_FullName, Messages.get().UserManagementView_Description, Messages.get().UserManagementView_Source, Messages.get().UserManagementView_Authentication, Messages.get().UserManagementView_GUID, "LDAP DN", "Last Login", "Created" };
    final int[] widths = { 100, 80, 180, 250, 80, 170, 250, 400, 250, 250 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new UserLabelProvider());
    viewer.setComparator(new UserComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEditUser.setEnabled(selection.size() == 1);
                actionChangePassword.setEnabled((selection.size() == 1) && (selection.getFirstElement() instanceof User));
                actionDeleteUser.setEnabled(selection.size() > 0);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEditUser.run();
        }
    });
    makeActions();
    contributeToActionBars();
    createPopupMenu();
    // Listener for server's notifications
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(final SessionNotification n) {
            if (n.getCode() == SessionNotification.USER_DB_CHANGED) {
                viewer.getControl().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        viewer.setInput(session.getUserDatabaseObjects());
                        if (editNewUser && (n.getSubCode() == SessionNotification.USER_DB_OBJECT_CREATED)) {
                            editNewUser = false;
                            viewer.setSelection(new StructuredSelection(n.getObject()), true);
                            actionEditUser.run();
                        }
                    }
                });
            }
        }
    };
    // Request server to lock user database, and on success refresh view
    new ConsoleJob(Messages.get().UserManagementView_OpenJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.lockUserDatabase();
            databaseLocked = true;
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(session.getUserDatabaseObjects());
                    session.addListener(sessionListener);
                }
            });
        }

        @Override
        protected void jobFailureHandler() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    UserManagementView.this.getViewSite().getPage().hideView(UserManagementView.this);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().UserManagementView_OpenJobError;
        }
    }.start();
}
Also used : UserLabelProvider(org.netxms.ui.eclipse.usermanager.views.helpers.UserLabelProvider) User(org.netxms.client.users.User) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) SessionNotification(org.netxms.client.SessionNotification)

Example 67 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class SelectUserDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    session = ConsoleSharedData.getSession();
    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().SelectUserDialog_AvailableUsers);
    final String[] columnNames = { Messages.get().SelectUserDialog_LoginName };
    final int[] columnWidths = { 250 };
    userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | (multiSelection ? SWT.MULTI : 0) | SWT.FULL_SELECTION);
    userList.setContentProvider(new ArrayContentProvider());
    userList.setLabelProvider(new WorkbenchLabelProvider());
    userList.setComparator(new UserComparator());
    userList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            SelectUserDialog.this.okPressed();
        }
    });
    userList.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return classFilter.isInstance(element);
        }
    });
    userList.setInput(session.getUserDatabaseObjects());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    userList.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) AbstractUserObject(org.netxms.client.users.AbstractUserObject)

Example 68 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class GroupMembership method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    session = ConsoleSharedData.getSession();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (User) getElement().getAdapter(User.class);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().GroupMembership_ColName };
    final int[] columnWidths = { 300 };
    groupList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    groupList.setContentProvider(new ArrayContentProvider());
    groupList.setLabelProvider(new WorkbenchLabelProvider());
    groupList.setComparator(new UserComparator());
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    groupList.getControl().setLayoutData(gd);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    FillLayout buttonsLayout = new FillLayout();
    buttonsLayout.spacing = WidgetHelper.INNER_SPACING;
    buttons.setLayout(buttonsLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.widthHint = 184;
    buttons.setLayoutData(gd);
    final Button addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().Members_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectUserDialog dlg = new SelectUserDialog(GroupMembership.this.getShell(), UserGroup.class);
            if (dlg.open() == Window.OK) {
                AbstractUserObject[] selection = dlg.getSelection();
                for (AbstractUserObject user : selection) groups.put(user.getId(), user);
                groupList.setInput(groups.values().toArray(new AbstractUserObject[groups.size()]));
            }
        }
    });
    final Button deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().Members_Delete);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        @SuppressWarnings("unchecked")
        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) groupList.getSelection();
            Iterator<AbstractUserObject> it = sel.iterator();
            while (it.hasNext()) {
                AbstractUserObject element = it.next();
                groups.remove(element.getId());
            }
            groupList.setInput(groups.values().toArray());
        }
    });
    groupList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            deleteButton.setEnabled(!groupList.getSelection().isEmpty());
        }
    });
    // Initial data
    for (long groupId : object.getGroups()) {
        final AbstractUserObject group = session.findUserDBObjectById(groupId);
        if (group != null) {
            groups.put(group.getId(), group);
        }
    }
    groupList.setInput(groups.values().toArray());
    return dialogArea;
}
Also used : SelectUserDialog(org.netxms.ui.eclipse.usermanager.dialogs.SelectUserDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) UserComparator(org.netxms.ui.eclipse.usermanager.views.helpers.UserComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) AbstractUserObject(org.netxms.client.users.AbstractUserObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UserGroup(org.netxms.client.users.UserGroup) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 69 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class ActionManager method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    parent.setLayout(new FillLayout());
    final String[] columnNames = { Messages.get().ActionManager_ColumnName, Messages.get().ActionManager_ColumnType, Messages.get().ActionManager_ColumnRcpt, Messages.get().ActionManager_ColumnSubj, Messages.get().ActionManager_ColumnData };
    final int[] columnWidths = { 150, 90, 100, 120, 200 };
    viewer = new SortableTableViewer(parent, columnNames, columnWidths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ActionLabelProvider());
    viewer.setComparator(new ActionComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEdit.run();
        }
    });
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
        }
    });
    createActions();
    contributeToActionBars();
    createPopupMenu();
    session.addListener(this);
    refreshActionList();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) ActionComparator(org.netxms.ui.eclipse.actionmanager.views.helpers.ActionComparator) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ActionLabelProvider(org.netxms.ui.eclipse.actionmanager.views.helpers.ActionLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider)

Example 70 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class TunnelManager method createPartControl.

/* (non-Javadoc)
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    parent.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(parent, SWT.NONE, null, true);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(false);
        }
    });
    final String[] names = { "ID", "State", "Node", "IP address", "Channels", "System name", "Hostname", "Platform", "System information", "Agent version" };
    final int[] widths = { 80, 80, 140, 150, 80, 150, 150, 250, 300, 150 };
    viewer = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new TunnelListLabelProvider());
    viewer.setComparator(new TunnelListComparator());
    filter = new TunnelManagerFilter();
    viewer.addFilter(filter);
    final IDialogSettings settings = Activator.getDefault().getDialogSettings();
    initShowfilter = settings.getBoolean(ID + "initShowFilter");
    WidgetHelper.restoreTableViewerSettings(viewer, settings, "TunnelManager");
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, settings, "TunnelManager");
            settings.put(ID + "initShowFilter", initShowfilter);
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getControl().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    activateContext();
    // Set initial focus to filter input line
    if (initShowfilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    refresh();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) DisposeListener(org.eclipse.swt.events.DisposeListener) Action(org.eclipse.jface.action.Action) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) TunnelListComparator(org.netxms.ui.eclipse.agentmanager.views.helpers.TunnelListComparator) ModifyListener(org.eclipse.swt.events.ModifyListener) TunnelListLabelProvider(org.netxms.ui.eclipse.agentmanager.views.helpers.TunnelListLabelProvider) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TunnelManagerFilter(org.netxms.ui.eclipse.agentmanager.views.helpers.TunnelManagerFilter) FilterText(org.netxms.ui.eclipse.widgets.FilterText) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)97 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)66 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)43 Composite (org.eclipse.swt.widgets.Composite)43 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridData (org.eclipse.swt.layout.GridData)38 GridLayout (org.eclipse.swt.layout.GridLayout)38 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)29 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28 Button (org.eclipse.swt.widgets.Button)28 SelectionListener (org.eclipse.swt.events.SelectionListener)27 DisposeEvent (org.eclipse.swt.events.DisposeEvent)26 DisposeListener (org.eclipse.swt.events.DisposeListener)26 RowLayout (org.eclipse.swt.layout.RowLayout)24 RowData (org.eclipse.swt.layout.RowData)20 Event (org.eclipse.swt.widgets.Event)14 FillLayout (org.eclipse.swt.layout.FillLayout)12 Iterator (java.util.Iterator)11