Search in sources :

Example 1 with Pair

use of com.haulmont.bali.datastruct.Pair in project cuba by cuba-platform.

the class EntityDiffManager method getCollectionDiff.

protected EntityPropertyDiff getCollectionDiff(Object firstValue, Object secondValue, ViewProperty viewProperty, MetaProperty metaProperty, Stack<Object> diffBranch) {
    EntityPropertyDiff propertyDiff = null;
    Collection<Entity> addedEntities = new LinkedList<>();
    Collection<Entity> removedEntities = new LinkedList<>();
    Collection<Pair<Entity, Entity>> modifiedEntities = new LinkedList<>();
    // collection
    Collection firstCollection = firstValue == null ? Collections.emptyList() : (Collection) firstValue;
    Collection secondCollection = secondValue == null ? Collections.emptyList() : (Collection) secondValue;
    // added or modified
    for (Object item : secondCollection) {
        Entity secondEntity = (Entity) item;
        Entity firstEntity = getRelatedItem(firstCollection, secondEntity);
        if (firstEntity == null)
            addedEntities.add(secondEntity);
        else
            modifiedEntities.add(new Pair<>(firstEntity, secondEntity));
    }
    // removed
    for (Object item : firstCollection) {
        Entity firstEntity = (Entity) item;
        Entity secondEntity = getRelatedItem(secondCollection, firstEntity);
        if (secondEntity == null)
            removedEntities.add(firstEntity);
    }
    boolean changed = !(addedEntities.isEmpty() && removedEntities.isEmpty() && modifiedEntities.isEmpty());
    if (changed) {
        EntityCollectionPropertyDiff diff = new EntityCollectionPropertyDiff(metaProperty);
        for (Entity entity : addedEntities) {
            EntityPropertyDiff addedDiff = getClassDiff(null, entity, viewProperty, metaProperty, diffBranch);
            if (addedDiff != null) {
                addedDiff.setName(InstanceUtils.getInstanceName(entity));
                addedDiff.setItemState(EntityPropertyDiff.ItemState.Added);
                diff.getAddedEntities().add(addedDiff);
            }
        }
        // check modified
        for (Pair<Entity, Entity> entityPair : modifiedEntities) {
            EntityPropertyDiff modifiedDiff = getClassDiff(entityPair.getFirst(), entityPair.getSecond(), viewProperty, metaProperty, diffBranch);
            if (modifiedDiff != null) {
                modifiedDiff.setName(InstanceUtils.getInstanceName(entityPair.getSecond()));
                modifiedDiff.setItemState(EntityPropertyDiff.ItemState.Modified);
                diff.getModifiedEntities().add(modifiedDiff);
            }
        }
        // check removed
        for (Entity entity : removedEntities) {
            EntityPropertyDiff removedDiff = getClassDiff(entity, null, viewProperty, metaProperty, diffBranch);
            if (removedDiff != null) {
                removedDiff.setName(InstanceUtils.getInstanceName(entity));
                removedDiff.setItemState(EntityPropertyDiff.ItemState.Removed);
                diff.getRemovedEntities().add(removedDiff);
            }
        }
        boolean empty = diff.getAddedEntities().isEmpty() && diff.getModifiedEntities().isEmpty() && diff.getRemovedEntities().isEmpty();
        if (!empty)
            propertyDiff = diff;
    }
    return propertyDiff;
}
Also used : EmbeddableEntity(com.haulmont.cuba.core.entity.EmbeddableEntity) Entity(com.haulmont.cuba.core.entity.Entity) Pair(com.haulmont.bali.datastruct.Pair)

Example 2 with Pair

use of com.haulmont.bali.datastruct.Pair in project cuba by cuba-platform.

the class ControlLoggerWindow method createEditComponents.

protected Pair<TextField, HBoxLayout> createEditComponents(String loggerName, Level level) {
    final TextField loggerNameField = componentsFactory.createComponent(TextField.class);
    loggerNameField.setValue(loggerName);
    loggerNameField.setEditable(false);
    loggerNameField.setFrame(this);
    loggerNameField.setWidth("100%");
    HBoxLayout buttonField = componentsFactory.createComponent(HBoxLayout.class);
    buttonField.setSpacing(true);
    for (Level logLevel : LoggingHelper.getLevels()) {
        if (logLevel != Level.OFF && logLevel != Level.ALL) {
            Button button = componentsFactory.createComponent(Button.class);
            button.setAction(new AbstractAction("setLevel") {

                @Override
                public void actionPerform(Component component) {
                    levels.put(loggerName, logLevel);
                    HBoxLayout buttonPanel = (HBoxLayout) button.getParent();
                    for (Component childButton : buttonPanel.getComponents()) {
                        if (childButton instanceof Button) {
                            childButton.setStyleName("c-logger-level loglevel-" + logLevel.toString());
                        }
                    }
                    button.setStyleName("c-logger-level loglevel-" + logLevel.toString() + " currentlevel");
                }
            });
            button.setCaption(logLevel.toString());
            if (logLevel == level) {
                button.setStyleName("c-logger-level loglevel-" + logLevel.toString() + " currentlevel");
            } else {
                button.setStyleName("c-logger-level loglevel-" + logLevel.toString());
            }
            buttonField.add(button);
        }
    }
    return new Pair<>(loggerNameField, buttonField);
}
Also used : Level(ch.qos.logback.classic.Level) Pair(com.haulmont.bali.datastruct.Pair)

Example 3 with Pair

use of com.haulmont.bali.datastruct.Pair in project cuba by cuba-platform.

the class MetadataLoader method replaceExtendedMetaClasses.

protected void replaceExtendedMetaClasses() {
    StopWatch sw = new Slf4JStopWatch("Metadata.replaceExtendedMetaClasses");
    for (MetaModel model : session.getModels()) {
        MetaModelImpl modelImpl = (MetaModelImpl) model;
        List<Pair<MetaClass, MetaClass>> replaceMap = new ArrayList<>();
        for (MetaClass metaClass : modelImpl.getClasses()) {
            MetaClass effectiveMetaClass = session.getClass(extendedEntities.getEffectiveClass(metaClass));
            if (effectiveMetaClass != metaClass) {
                replaceMap.add(new Pair<>(metaClass, effectiveMetaClass));
            }
            for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
                MetaPropertyImpl propertyImpl = (MetaPropertyImpl) metaProperty;
                // replace domain
                Class effectiveDomainClass = extendedEntities.getEffectiveClass(metaProperty.getDomain());
                MetaClass effectiveDomainMeta = session.getClass(effectiveDomainClass);
                if (metaProperty.getDomain() != effectiveDomainMeta) {
                    propertyImpl.setDomain(effectiveDomainMeta);
                }
                if (metaProperty.getRange().isClass()) {
                    // replace range class
                    ClassRange range = (ClassRange) metaProperty.getRange();
                    Class effectiveRangeClass = extendedEntities.getEffectiveClass(range.asClass());
                    MetaClass effectiveRangeMeta = session.getClass(effectiveRangeClass);
                    if (effectiveRangeMeta != range.asClass()) {
                        ClassRange newRange = new ClassRange(effectiveRangeMeta);
                        newRange.setCardinality(range.getCardinality());
                        newRange.setOrdered(range.isOrdered());
                        ((MetaPropertyImpl) metaProperty).setRange(newRange);
                    }
                }
            }
        }
        for (Pair<MetaClass, MetaClass> replace : replaceMap) {
            MetaClass replacedMetaClass = replace.getFirst();
            extendedEntities.registerReplacedMetaClass(replacedMetaClass);
            MetaClassImpl effectiveMetaClass = (MetaClassImpl) replace.getSecond();
            modelImpl.registerClass(replacedMetaClass.getName(), replacedMetaClass.getJavaClass(), effectiveMetaClass);
        }
    }
    sw.stop();
}
Also used : Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) Slf4JStopWatch(org.perf4j.slf4j.Slf4JStopWatch) StopWatch(org.perf4j.StopWatch) MetaModel(com.haulmont.chile.core.model.MetaModel) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaClass(com.haulmont.chile.core.model.MetaClass) MetaProperty(com.haulmont.chile.core.model.MetaProperty) Pair(com.haulmont.bali.datastruct.Pair)

Example 4 with Pair

use of com.haulmont.bali.datastruct.Pair in project cuba by cuba-platform.

the class WebWindowManager method closeWindow.

protected void closeWindow(Window window, WindowOpenInfo openInfo) {
    if (!disableSavingScreenHistory) {
        screenHistorySupport.saveScreenHistory(window, openInfo.getOpenMode());
    }
    WebWindow webWindow = (WebWindow) window;
    webWindow.stopTimers();
    switch(openInfo.getOpenMode()) {
        case DIALOG:
            {
                final CubaWindow cubaDialogWindow = (CubaWindow) openInfo.getData();
                cubaDialogWindow.forceClose();
                fireListeners(window, tabs.size() != 0);
                break;
            }
        case NEW_WINDOW:
        case NEW_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                if (workArea.getMode() == Mode.TABBED) {
                    TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                    tabSheet.silentCloseTabAndSelectPrevious(layout);
                    tabSheet.removeComponent(layout);
                } else {
                    VerticalLayout singleLayout = workArea.getSingleWindowContainer();
                    singleLayout.removeComponent(layout);
                }
                WindowBreadCrumbs windowBreadCrumbs = tabs.get(layout);
                if (windowBreadCrumbs != null) {
                    windowBreadCrumbs.clearListeners();
                    windowBreadCrumbs.removeWindow();
                }
                tabs.remove(layout);
                stacks.remove(windowBreadCrumbs);
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        case THIS_TAB:
            {
                final Layout layout = (Layout) openInfo.getData();
                final WindowBreadCrumbs breadCrumbs = tabs.get(layout);
                if (breadCrumbs == null) {
                    throw new IllegalStateException("Unable to close screen: breadCrumbs not found");
                }
                breadCrumbs.removeWindow();
                Window currentWindow = breadCrumbs.getCurrentWindow();
                if (!getStack(breadCrumbs).empty()) {
                    Pair<Window, Integer> entry = getStack(breadCrumbs).pop();
                    putToWindowMap(entry.getFirst(), entry.getSecond());
                }
                Component component = WebComponentsHelper.getComposition(currentWindow);
                component.setSizeFull();
                WebAppWorkArea workArea = getConfiguredWorkArea(createWorkAreaContext(window));
                layout.removeComponent(WebComponentsHelper.getComposition(window));
                if (app.getConnection().isConnected()) {
                    layout.addComponent(component);
                    if (workArea.getMode() == Mode.TABBED) {
                        TabSheetBehaviour tabSheet = workArea.getTabbedWindowContainer().getTabSheetBehaviour();
                        String tabId = tabSheet.getTab(layout);
                        String formattedCaption = formatTabCaption(currentWindow.getCaption(), currentWindow.getDescription());
                        tabSheet.setTabCaption(tabId, formattedCaption);
                        String formattedDescription = formatTabDescription(currentWindow.getCaption(), currentWindow.getDescription());
                        if (!Objects.equals(formattedCaption, formattedDescription)) {
                            tabSheet.setTabDescription(tabId, formattedDescription);
                        } else {
                            tabSheet.setTabDescription(tabId, null);
                        }
                        tabSheet.setTabIcon(tabId, iconResolver.getIconResource(currentWindow.getIcon()));
                        ContentSwitchMode contentSwitchMode = ContentSwitchMode.valueOf(currentWindow.getContentSwitchMode().name());
                        tabSheet.setContentSwitchMode(tabId, contentSwitchMode);
                    }
                }
                fireListeners(window, !tabs.isEmpty());
                if (tabs.isEmpty() && app.getConnection().isConnected()) {
                    workArea.switchTo(AppWorkArea.State.INITIAL_LAYOUT);
                }
                break;
            }
        default:
            {
                throw new UnsupportedOperationException();
            }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebWindow(com.haulmont.cuba.web.gui.WebWindow) WebAppWorkArea(com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea) CssLayout(com.vaadin.ui.CssLayout) WindowBreadCrumbs(com.haulmont.cuba.web.sys.WindowBreadCrumbs) WebAbstractComponent(com.haulmont.cuba.web.gui.components.WebAbstractComponent) Component(com.vaadin.ui.Component) Pair(com.haulmont.bali.datastruct.Pair)

Example 5 with Pair

use of com.haulmont.bali.datastruct.Pair in project cuba by cuba-platform.

the class LayoutLoader method createFrameComponent.

public Pair<ComponentLoader, Element> createFrameComponent(String resourcePath, String id, Map<String, Object> params) {
    ScreenXmlLoader screenXmlLoader = AppBeans.get(ScreenXmlLoader.class);
    Element element = screenXmlLoader.load(resourcePath, id, params);
    ComponentLoader loader = getLoader(element);
    FrameLoader frameLoader = (FrameLoader) loader;
    frameLoader.setFrameId(id);
    loader.createComponent();
    return new Pair<>(loader, element);
}
Also used : Element(org.dom4j.Element) FrameLoader(com.haulmont.cuba.gui.xml.layout.loaders.FrameLoader) Pair(com.haulmont.bali.datastruct.Pair)

Aggregations

Pair (com.haulmont.bali.datastruct.Pair)5 Level (ch.qos.logback.classic.Level)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaModel (com.haulmont.chile.core.model.MetaModel)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 EmbeddableEntity (com.haulmont.cuba.core.entity.EmbeddableEntity)1 Entity (com.haulmont.cuba.core.entity.Entity)1 Window (com.haulmont.cuba.gui.components.Window)1 FrameLoader (com.haulmont.cuba.gui.xml.layout.loaders.FrameLoader)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1 WindowBreadCrumbs (com.haulmont.cuba.web.sys.WindowBreadCrumbs)1 Component (com.vaadin.ui.Component)1 CssLayout (com.vaadin.ui.CssLayout)1 Element (org.dom4j.Element)1 StopWatch (org.perf4j.StopWatch)1 Slf4JStopWatch (org.perf4j.slf4j.Slf4JStopWatch)1