Search in sources :

Example 1 with OrderedComparator

use of org.eclipse.scout.rt.platform.OrderedComparator in project scout.rt by eclipse.

the class AbstractDesktop method initConfig.

protected void initConfig() {
    m_eventHistory = createEventHistory();
    // add convenience observer for event history
    addDesktopListener(new DesktopListener() {

        @Override
        public void desktopChanged(DesktopEvent e) {
            IEventHistory<DesktopEvent> h = getEventHistory();
            if (h != null) {
                h.notifyEvent(e);
            }
        }
    });
    ClientSessionProvider.currentSession().getMemoryPolicy().registerDesktop(this);
    BEANS.get(IDeviceTransformationService.class).install(this);
    initDesktopExtensions();
    setTitle(getConfiguredTitle());
    setCssClass(getConfiguredCssClass());
    setSelectViewTabsKeyStrokesEnabled(getConfiguredSelectViewTabsKeyStrokesEnabled());
    setSelectViewTabsKeyStrokeModifier(getConfiguredSelectViewTabsKeyStrokeModifier());
    setLogoId(getConfiguredLogoId());
    setDisplayStyle(getConfiguredDisplayStyle());
    initDisplayStyle(getDisplayStyle());
    setCacheSplitterPosition(getConfiguredCacheSplitterPosition());
    List<IDesktopExtension> extensions = getDesktopExtensions();
    m_contributionHolder = new ContributionComposite(this);
    // outlines
    OrderedCollection<IOutline> outlines = new OrderedCollection<IOutline>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeOutlines(outlines);
        } catch (Exception t) {
            LOG.error("contributing outlines by {}", ext, t);
        }
    }
    List<IOutline> contributedOutlines = m_contributionHolder.getContributionsByClass(IOutline.class);
    outlines.addAllOrdered(contributedOutlines);
    // move outlines
    ExtensionUtility.moveModelObjects(outlines);
    setAvailableOutlines(outlines.getOrderedList());
    // actions (keyStroke, menu, viewButton, toolButton)
    List<IAction> actionList = new ArrayList<IAction>();
    for (IDesktopExtension ext : extensions) {
        try {
            ext.contributeActions(actionList);
        } catch (Exception t) {
            LOG.error("contributing actions by {}", ext, t);
        }
    }
    List<IAction> contributedActions = m_contributionHolder.getContributionsByClass(IAction.class);
    actionList.addAll(contributedActions);
    // build complete menu and viewButton lists
    // only top level menus
    OrderedComparator orderedComparator = new OrderedComparator();
    List<IMenu> menuList = new ActionFinder().findActions(actionList, IMenu.class, false);
    ExtensionUtility.moveModelObjects(menuList);
    Collections.sort(menuList, orderedComparator);
    m_menus = menuList;
    List<IViewButton> viewButtonList = new ActionFinder().findActions(actionList, IViewButton.class, false);
    ExtensionUtility.moveModelObjects(viewButtonList);
    Collections.sort(viewButtonList, orderedComparator);
    m_viewButtons = viewButtonList;
    // add dynamic keyStrokes
    List<IKeyStroke> ksList = new ActionFinder().findActions(actionList, IKeyStroke.class, true);
    for (IKeyStroke ks : ksList) {
        try {
            ks.initAction();
        } catch (RuntimeException | PlatformError e) {
            LOG.error("could not initialize key stroke '{}'.", ks, e);
        }
    }
    addKeyStrokes(ksList.toArray(new IKeyStroke[ksList.size()]));
    // init outlines
    for (IOutline o : m_availableOutlines) {
        try {
            o.initTree();
        } catch (Exception e) {
            LOG.error("Could not init outline {}", o, e);
        }
    }
    addPropertyChangeListener(new P_LocalPropertyChangeListener());
}
Also used : IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) IEventHistory(org.eclipse.scout.rt.client.ui.IEventHistory) IKeyStroke(org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) IAction(org.eclipse.scout.rt.client.ui.action.IAction) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) DeepLinkException(org.eclipse.scout.rt.client.deeplink.DeepLinkException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) PlatformError(org.eclipse.scout.rt.platform.exception.PlatformError) IViewButton(org.eclipse.scout.rt.client.ui.action.view.IViewButton) IDeviceTransformationService(org.eclipse.scout.rt.client.transformation.IDeviceTransformationService) ActionFinder(org.eclipse.scout.rt.client.ui.action.ActionFinder)

Example 2 with OrderedComparator

use of org.eclipse.scout.rt.platform.OrderedComparator in project scout.rt by eclipse.

the class CompositeFieldUtility method addField.

public static void addField(IFormField f, ICompositeField compositeField, List<IFormField> fields) {
    checkFieldStateForMove(f);
    checkFieldStateForMove(compositeField);
    if (f.getParentField() != null) {
        throw new IllegalArgumentException("field is already contained in '" + f.getParentField() + "'");
    }
    if (f.getForm() != null && f.getForm() != compositeField.getForm()) {
        throw new IllegalArgumentException("field is part of a different form,  '" + f.getForm() + "' instead of '" + compositeField.getForm() + "'");
    }
    fields.add(f);
    Collections.sort(fields, new OrderedComparator());
    f.setParentFieldInternal(compositeField);
    f.setFormInternal(compositeField.getForm());
}
Also used : OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator)

Example 3 with OrderedComparator

use of org.eclipse.scout.rt.platform.OrderedComparator in project scout.rt by eclipse.

the class AbstractTable method addTableControlInternal.

private void addTableControlInternal(ITableControl control) {
    ((AbstractTableControl) control).setTable(this);
    Collections.sort(m_tableControls, new OrderedComparator());
    propertySupport.firePropertyChange(PROP_TABLE_CONTROLS, null, getTableControls());
}
Also used : AbstractTableControl(org.eclipse.scout.rt.client.ui.basic.table.controls.AbstractTableControl) OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator)

Example 4 with OrderedComparator

use of org.eclipse.scout.rt.platform.OrderedComparator in project scout.rt by eclipse.

the class AbstractActionNode method addChildActions.

@Override
public void addChildActions(Collection<? extends T> actionList) {
    List<T> normalizedList = CollectionUtility.arrayListWithoutNullElements(actionList);
    if (!normalizedList.isEmpty()) {
        setContainerOnActions(normalizedList);
        List<T> childList = getChildActionsInternal();
        if (childList == null) {
            childList = new ArrayList<T>(normalizedList.size());
        }
        childList.addAll(normalizedList);
        Collections.sort(childList, new OrderedComparator());
        propertySupport.setPropertyAlwaysFire(PROP_CHILD_ACTIONS, childList);
    }
}
Also used : OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator)

Example 5 with OrderedComparator

use of org.eclipse.scout.rt.platform.OrderedComparator in project scout.rt by eclipse.

the class OrderedComparatorTest method testCompare.

@Test
public void testCompare() {
    OrderedComparator comparator = new OrderedComparator();
    IFormField f1 = Mockito.mock(IFormField.class);
    IFormField f2 = Mockito.mock(IFormField.class);
    Mockito.when(f1.getOrder()).thenReturn(10d);
    Mockito.when(f2.getOrder()).thenReturn(20d);
    Assert.assertEquals(0, comparator.compare(null, null));
    Assert.assertEquals(-1, comparator.compare(null, f1));
    Assert.assertEquals(1, comparator.compare(f1, null));
    Assert.assertEquals(-1, comparator.compare(f1, f2));
    Assert.assertEquals(1, comparator.compare(f2, f1));
    Assert.assertEquals(0, comparator.compare(f1, f1));
}
Also used : OrderedComparator(org.eclipse.scout.rt.platform.OrderedComparator) Test(org.junit.Test)

Aggregations

OrderedComparator (org.eclipse.scout.rt.platform.OrderedComparator)9 ArrayList (java.util.ArrayList)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)2 DeepLinkException (org.eclipse.scout.rt.client.deeplink.DeepLinkException)1 IDeviceTransformationService (org.eclipse.scout.rt.client.transformation.IDeviceTransformationService)1 IEventHistory (org.eclipse.scout.rt.client.ui.IEventHistory)1 ActionFinder (org.eclipse.scout.rt.client.ui.action.ActionFinder)1 IAction (org.eclipse.scout.rt.client.ui.action.IAction)1 IKeyStroke (org.eclipse.scout.rt.client.ui.action.keystroke.IKeyStroke)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 IViewButton (org.eclipse.scout.rt.client.ui.action.view.IViewButton)1 AbstractTable (org.eclipse.scout.rt.client.ui.basic.table.AbstractTable)1 ITable (org.eclipse.scout.rt.client.ui.basic.table.ITable)1 TableAdapter (org.eclipse.scout.rt.client.ui.basic.table.TableAdapter)1 TableEvent (org.eclipse.scout.rt.client.ui.basic.table.TableEvent)1 AbstractTableControl (org.eclipse.scout.rt.client.ui.basic.table.controls.AbstractTableControl)1 AbstractTree (org.eclipse.scout.rt.client.ui.basic.tree.AbstractTree)1 ITree (org.eclipse.scout.rt.client.ui.basic.tree.ITree)1