Search in sources :

Example 1 with ImageCache

use of org.netxms.ui.eclipse.tools.ImageCache in project netxms by netxms.

the class AlarmComments method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    imageCache = new ImageCache();
    toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createScrolledForm(parent);
    TableWrapLayout layout = new TableWrapLayout();
    layout.numColumns = 1;
    form.getBody().setLayout(layout);
    createAlarmDetailsSection();
    createEditorsSection();
    createActions();
    contributeToActionBars();
    refresh();
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) TableWrapLayout(org.eclipse.ui.forms.widgets.TableWrapLayout) ImageCache(org.netxms.ui.eclipse.tools.ImageCache)

Example 2 with ImageCache

use of org.netxms.ui.eclipse.tools.ImageCache in project netxms by netxms.

the class ObjectToolsDynamicMenu method fill.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
	 */
@Override
public void fill(Menu menu, int index) {
    Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection))
        return;
    final Set<ObjectContext> nodes = buildNodeSet((IStructuredSelection) selection);
    final Menu toolsMenu = new Menu(menu);
    final ImageCache imageCache = new ImageCache();
    toolsMenu.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            imageCache.dispose();
        }
    });
    ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
    Arrays.sort(tools, new Comparator<ObjectTool>() {

        @Override
        public int compare(ObjectTool arg0, ObjectTool arg1) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return arg0.getName().replace("&", "").compareToIgnoreCase(arg1.getName().replace("&", ""));
        }
    });
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < tools.length; i++) {
        boolean enabled = (tools[i].getFlags() & ObjectTool.DISABLED) == 0;
        if (enabled && ObjectToolExecutor.isToolAllowed(tools[i], nodes) && ObjectToolExecutor.isToolApplicable(tools[i], nodes)) {
            // $NON-NLS-1$
            String[] path = tools[i].getName().split("\\-\\>");
            Menu rootMenu = toolsMenu;
            for (int j = 0; j < path.length - 1; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                final String key = rootMenu.hashCode() + "@" + path[j].replace("&", "");
                Menu currMenu = menus.get(key);
                if (currMenu == null) {
                    currMenu = new Menu(rootMenu);
                    MenuItem item = new MenuItem(rootMenu, SWT.CASCADE);
                    item.setText(path[j]);
                    item.setMenu(currMenu);
                    menus.put(key, currMenu);
                }
                rootMenu = currMenu;
            }
            final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
            item.setText(path[path.length - 1]);
            ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tools[i].getId());
            if (icon != null)
                item.setImage(imageCache.add(icon));
            item.setData(tools[i]);
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ObjectToolExecutor.execute(nodes, (ObjectTool) item.getData());
                }
            });
            added++;
        }
    }
    if (added > 0) {
        MenuItem toolsMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        toolsMenuItem.setText(Messages.get().ObjectToolsDynamicMenu_TopLevelLabel);
        toolsMenuItem.setMenu(toolsMenu);
    } else {
        toolsMenu.dispose();
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ImageCache(org.netxms.ui.eclipse.tools.ImageCache) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext) Menu(org.eclipse.swt.widgets.Menu) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 3 with ImageCache

use of org.netxms.ui.eclipse.tools.ImageCache in project netxms by netxms.

the class DateFieldEditor method createContent.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.reporter.widgets.FieldEditor#createContent(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContent(Composite parent) {
    final ImageCache imageCache = new ImageCache(this);
    final Composite content = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.horizontalSpacing = WidgetHelper.INNER_SPACING;
    layout.makeColumnsEqualWidth = true;
    content.setLayout(layout);
    Calendar dateTime = Calendar.getInstance();
    try {
        dateTime.setTime(new Date(Long.parseLong(parameter.getDefaultValue()) * 1000));
    } catch (NumberFormatException e) {
        dateTime.setTime(new Date());
    }
    final String[] dateElementNames = { Messages.get().DateFieldEditor_Year, Messages.get().DateFieldEditor_Month, Messages.get().DateFieldEditor_Day };
    dateElements = new Combo[dateElementNames.length];
    for (int idx = 0; idx < dateElementNames.length; idx++) {
        Combo cb = WidgetHelper.createLabeledCombo(content, SWT.BORDER, dateElementNames[idx], WidgetHelper.DEFAULT_LAYOUT_DATA);
        cb.setText(getDateTimeText(idx, dateTime));
        // $NON-NLS-1$
        cb.add("current");
        // $NON-NLS-1$
        cb.add("previous");
        // $NON-NLS-1$
        cb.add("next");
        dateElements[idx] = cb;
    }
    final ImageHyperlink link = toolkit.createImageHyperlink(content, SWT.NONE);
    // $NON-NLS-1$
    link.setImage(imageCache.add(Activator.getImageDescriptor("icons/calendar.png")));
    link.setToolTipText(Messages.get().DateFieldEditor_Calendar);
    link.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            createPopupCalendar(link);
        }
    });
    GridData gd = new GridData();
    gd.verticalAlignment = SWT.BOTTOM;
    gd.horizontalAlignment = SWT.LEFT;
    link.setLayoutData(gd);
    return content;
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) Calendar(java.util.Calendar) Combo(org.eclipse.swt.widgets.Combo) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) ImageCache(org.netxms.ui.eclipse.tools.ImageCache) GridData(org.eclipse.swt.layout.GridData) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 4 with ImageCache

use of org.netxms.ui.eclipse.tools.ImageCache in project netxms by netxms.

the class AlarmDetails method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    imageCache = new ImageCache();
    scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
    scroller.setExpandVertical(true);
    formContainer = new Composite(scroller, SWT.NONE);
    GridLayout containerLayout = new GridLayout();
    containerLayout.marginHeight = 0;
    containerLayout.marginWidth = 0;
    formContainer.setLayout(containerLayout);
    scroller.setContent(formContainer);
    scroller.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            Rectangle r = scroller.getClientArea();
            Point formSize = formContainer.computeSize(r.width, SWT.DEFAULT);
            formContainer.setSize(r.width, formSize.y);
            scroller.setMinHeight(formSize.y);
        }
    });
    toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createForm(formContainer);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    form.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    form.getBody().setLayout(layout);
    createAlarmDetailsSection();
    createEventsSection();
    createCommentsSection();
    createDataSection();
    createActions();
    contributeToActionBars();
    refresh();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) ImageCache(org.netxms.ui.eclipse.tools.ImageCache) Rectangle(org.eclipse.swt.graphics.Rectangle) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Point(org.eclipse.swt.graphics.Point) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ImageCache (org.netxms.ui.eclipse.tools.ImageCache)4 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Combo (org.eclipse.swt.widgets.Combo)1