Search in sources :

Example 6 with DevelopmentException

use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.

the class RuntimePropertiesFrame method initDatasources.

protected void initDatasources(Map<String, Object> params) {
    String dsId = (String) params.get("runtimeDs");
    if (dsId == null)
        throw new DevelopmentException("runtimeProperties initialization error: runtimeDs is not provided");
    rds = (RuntimePropsDatasource) getDsContext().get(dsId);
    if (rds == null)
        throw new DevelopmentException("runtimeProperties initialization error: runtimeDs '" + dsId + "' does not exists");
    String categoriesDsId = (String) params.get("categoriesDs");
    if (categoriesDsId == null)
        throw new DevelopmentException("runtimeProperties initialization error: categoriesDs is not provided");
    categoriesDs = (CollectionDatasource) getDsContext().get(categoriesDsId);
    if (categoriesDs == null)
        throw new DevelopmentException("runtimeProperties initialization error: categoriesDs '" + categoriesDsId + "' does not exists");
}
Also used : DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 7 with DevelopmentException

use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.

the class DesktopComponentsFactory method createComponent.

@Override
public <T extends Component> T createComponent(Class<T> type) {
    String name = names.get(type);
    if (name == null) {
        java.lang.reflect.Field nameField;
        try {
            nameField = type.getField("NAME");
            name = (String) nameField.get(null);
        } catch (NoSuchFieldException | IllegalAccessException ignore) {
        }
        if (name == null)
            throw new DevelopmentException(String.format("Class '%s' doesn't have NAME field", type.getName()));
        else
            names.put(type, name);
    }
    return type.cast(createComponent(name));
}
Also used : DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 8 with DevelopmentException

use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.

the class WebComponentsFactory method createComponent.

@Override
public <T extends Component> T createComponent(Class<T> type) {
    String name = names.get(type);
    if (name == null) {
        java.lang.reflect.Field nameField;
        try {
            nameField = type.getField("NAME");
            name = (String) nameField.get(null);
        } catch (NoSuchFieldException | IllegalAccessException ignore) {
        }
        if (name == null)
            throw new DevelopmentException(String.format("Class '%s' doesn't have NAME field", type.getName()));
        else
            names.put(type, name);
    }
    return type.cast(createComponent(name));
}
Also used : DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 9 with DevelopmentException

use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.

the class WindowConfig method loadConfig.

@SuppressWarnings("unchecked")
protected void loadConfig(Element rootElem) {
    for (Element element : (List<Element>) rootElem.elements("include")) {
        String fileName = element.attributeValue("file");
        if (!StringUtils.isBlank(fileName)) {
            String incXml = resources.getResourceAsString(fileName);
            if (incXml == null) {
                log.warn("File {} not found, ignore it", fileName);
                continue;
            }
            loadConfig(Dom4j.readDocument(incXml).getRootElement());
        }
    }
    for (Element element : (List<Element>) rootElem.elements("screen")) {
        String id = element.attributeValue("id");
        if (StringUtils.isBlank(id)) {
            log.warn("Invalid window config: 'id' attribute not defined");
            continue;
        }
        ScreenAgent targetAgent = null;
        String agent = element.attributeValue("agent");
        if (StringUtils.isNotEmpty(agent)) {
            targetAgent = activeScreenAgents.get(agent);
            if (targetAgent == null) {
                throw new DevelopmentException("Unable to find target screen agent", "agent", agent);
            }
        }
        WindowInfo windowInfo = new WindowInfo(id, element, targetAgent);
        List<WindowInfo> screenInfos = screens.get(id);
        if (screenInfos == null) {
            screenInfos = new ArrayList<>();
            screens.put(id, screenInfos);
        } else {
            WindowInfo existingScreen = screenInfos.stream().filter(existingWindowInfo -> existingWindowInfo.getScreenAgent() == windowInfo.getScreenAgent()).findFirst().orElse(null);
            if (existingScreen != null) {
                screenInfos.remove(existingScreen);
            }
        }
        screenInfos.add(windowInfo);
    }
}
Also used : Element(org.dom4j.Element) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Example 10 with DevelopmentException

use of com.haulmont.cuba.core.global.DevelopmentException in project cuba by cuba-platform.

the class PropertyDatasourceImpl method getView.

@Override
public View getView() {
    if (view == null) {
        MetaClass metaMetaClass = masterDs.getMetaClass();
        if (metadata.getTools().isPersistent(metaMetaClass) || metadata.getTools().isEmbeddable(metaMetaClass)) {
            View masterView = masterDs.getView();
            if (masterView == null) {
                throw new DevelopmentException("No view for datasource " + masterDs.getId(), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId()));
            }
            ViewProperty property = masterView.getProperty(metaProperty.getName());
            if (property == null) {
                return null;
            }
            if (property.getView() == null) {
                throw new DevelopmentException(String.format("Invalid view definition: %s. Property '%s' must have a view", masterView, property), ParamsMap.of("masterDs", masterDs.getId(), "propertyDs", getId(), "masterView", masterView, "property", property));
            }
            view = metadata.getViewRepository().findView(getMetaClass(), property.getView().getName());
            // anonymous (nameless) view
            if (view == null)
                view = property.getView();
        }
    }
    return view;
}
Also used : MetaClass(com.haulmont.chile.core.model.MetaClass) ViewProperty(com.haulmont.cuba.core.global.ViewProperty) View(com.haulmont.cuba.core.global.View) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Aggregations

DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)16 MetaClass (com.haulmont.chile.core.model.MetaClass)4 Element (org.dom4j.Element)3 InputStream (java.io.InputStream)2 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 View (com.haulmont.cuba.core.global.View)1 ViewProperty (com.haulmont.cuba.core.global.ViewProperty)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 Component (com.haulmont.cuba.gui.components.Component)1 Window (com.haulmont.cuba.gui.components.Window)1 AppWorkArea (com.haulmont.cuba.gui.components.mainwindow.AppWorkArea)1 FoldersPane (com.haulmont.cuba.gui.components.mainwindow.FoldersPane)1 TopLevelWindowAttachListener (com.haulmont.cuba.gui.components.mainwindow.TopLevelWindowAttachListener)1 UserIndicator (com.haulmont.cuba.gui.components.mainwindow.UserIndicator)1 WebWindow (com.haulmont.cuba.web.gui.WebWindow)1 WebAppWorkArea (com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea)1 PresentationEditor (com.haulmont.cuba.web.gui.components.presentations.PresentationEditor)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1