Search in sources :

Example 21 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DesktopWindow method add.

@Override
public void add(Component component, int index) {
    if (component.getParent() != null && component.getParent() != this) {
        throw new IllegalStateException("Component already has parent");
    }
    if (ownComponents.contains(component)) {
        int existingIndex = new ArrayList<>(ownComponents).indexOf(component);
        if (index > existingIndex) {
            index--;
        }
        remove(component);
    }
    JComponent composition = DesktopComponentsHelper.getComposition(component);
    boolean hasExternalCaption = DesktopContainerHelper.hasExternalCaption(component);
    if (hasExternalCaption || DesktopContainerHelper.hasExternalContextHelp(component)) {
        ComponentCaption caption = new ComponentCaption(component);
        captions.put(component, caption);
        JPanel wrapper = new JPanel();
        BoxLayoutAdapter adapter = BoxLayoutAdapter.create(wrapper);
        adapter.setExpandLayout(true);
        adapter.setSpacing(false);
        adapter.setMargin(false);
        wrapper.add(composition);
        if (hasExternalCaption) {
            adapter.setFlowDirection(BoxLayoutAdapter.FlowDirection.Y);
            wrapper.add(caption, 0);
        } else {
            wrapper.add(caption, new CC().alignY("top"));
        }
        getContainer().add(wrapper, layoutAdapter.getConstraints(component), index);
        wrappers.put(component, new Pair<>(wrapper, adapter));
    } else {
        getContainer().add(composition, layoutAdapter.getConstraints(component), index);
    }
    if (component.getId() != null) {
        componentByIds.put(component.getId(), component);
    }
    if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
        ((BelongToFrame) component).setFrame(this);
    } else {
        registerComponent(component);
    }
    if (index == ownComponents.size()) {
        ownComponents.add(component);
    } else {
        List<Component> componentsTempList = new ArrayList<>(ownComponents);
        componentsTempList.add(index, component);
        ownComponents.clear();
        ownComponents.addAll(componentsTempList);
    }
    DesktopContainerHelper.assignContainer(component, this);
    if (component instanceof DesktopAbstractComponent && !isEnabled()) {
        ((DesktopAbstractComponent) component).setParentEnabled(false);
    }
    component.setParent(this);
    requestRepaint();
}
Also used : CC(net.miginfocom.layout.CC) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter) Component(com.haulmont.cuba.gui.components.Component) JTextComponent(javax.swing.text.JTextComponent)

Example 22 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DesktopExportDisplay method show.

/**
 * Show/Download resource at client side
 *
 * @param dataProvider {@link ExportDataProvider}
 * @param resourceName ResourceName for client side
 * @param format       {@link ExportFormat}
 * @see com.haulmont.cuba.gui.export.FileDataProvider
 * @see com.haulmont.cuba.gui.export.ByteArrayDataProvider
 */
@Override
public void show(final ExportDataProvider dataProvider, String resourceName, ExportFormat format) {
    backgroundWorker.checkUIAccess();
    String fileName = resourceName;
    if (format != null) {
        if (StringUtils.isEmpty(getFileExt(fileName)))
            fileName += "." + format.getFileExt();
    }
    String dialogMessage = messages.getMessage(getClass(), "export.saveFile");
    String correctName = StringUtils.replaceChars(fileName, RESERVED_SYMBOLS, "_");
    dialogMessage = String.format(dialogMessage, correctName);
    final String finalFileName = correctName;
    String fileCaption = messages.getMessage(getClass(), "export.fileCaption");
    getFrame().getWindowManager().showOptionDialog(fileCaption, dialogMessage, Frame.MessageType.CONFIRMATION, new com.haulmont.cuba.gui.components.Action[] { new AbstractAction("action.openFile", Status.PRIMARY) {

        @Override
        public void actionPerform(Component component) {
            openFileAction(finalFileName, dataProvider);
        }
    }, new AbstractAction("action.saveFile") {

        @Override
        public void actionPerform(Component component) {
            saveFileAction(finalFileName, getFrame(), dataProvider);
        }
    }, new AbstractAction("actions.Cancel") {

        @Override
        public void actionPerform(Component component) {
        // do nothing
        }
    } });
}
Also used : Component(com.haulmont.cuba.gui.components.Component) AbstractAction(com.haulmont.cuba.gui.components.AbstractAction)

Example 23 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DesktopFieldGroup method addCustomField.

@Override
public void addCustomField(FieldConfig fc, CustomFieldGenerator fieldGenerator) {
    if (!fc.isCustom()) {
        throw new IllegalStateException(String.format("Field '%s' must be defined as custom", fc.getId()));
    }
    FieldConfigImpl fci = (FieldConfigImpl) fc;
    Component fieldComponent = fieldGenerator.generateField(fc.getTargetDatasource(), fci.getTargetProperty());
    fc.setComponent(fieldComponent);
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Example 24 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DesktopFieldGroup method requestFocus.

@Override
public void requestFocus(String fieldId) {
    FieldConfig field = getFieldNN(fieldId);
    Component componentField = field.getComponentNN();
    componentField.requestFocus();
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Example 25 with Component

use of com.haulmont.cuba.gui.components.Component in project cuba by cuba-platform.

the class DesktopFieldGroup method validate.

@Override
public void validate() throws ValidationException {
    if (!isVisible() || !isEditableWithParent() || !isEnabled()) {
        return;
    }
    // lazily initialized
    Map<Component.Validatable, ValidationException> problemFields = null;
    // validate column by column
    List<FieldConfig> fieldsByColumns = getColumnOrderedFields();
    for (FieldConfig fc : fieldsByColumns) {
        Component fieldComponent = fc.getComponent();
        // If has valid state
        if ((fieldComponent instanceof Validatable) && (fieldComponent instanceof Editable)) {
            // If editable
            try {
                ((Validatable) fieldComponent).validate();
            } catch (ValidationException ex) {
                if (problemFields == null) {
                    problemFields = new LinkedHashMap<>();
                }
                problemFields.put((Validatable) fieldComponent, ex);
            }
        }
    }
    if (problemFields != null && !problemFields.isEmpty()) {
        FieldsValidationException validationException = new FieldsValidationException();
        validationException.setProblemFields(problemFields);
        throw validationException;
    }
}
Also used : Component(com.haulmont.cuba.gui.components.Component)

Aggregations

Component (com.haulmont.cuba.gui.components.Component)78 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)10 Datasource (com.haulmont.cuba.gui.data.Datasource)10 User (com.haulmont.cuba.security.entity.User)9 List (java.util.List)9 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)8 ArrayList (java.util.ArrayList)8 UUID (java.util.UUID)8 LookupPickerField (com.haulmont.cuba.gui.components.LookupPickerField)7 Group (com.haulmont.cuba.security.entity.Group)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 Element (org.dom4j.Element)6 ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)5 AbstractAction (com.haulmont.cuba.gui.components.AbstractAction)5 Frame (com.haulmont.cuba.gui.components.Frame)4 AbstractComponent (com.vaadin.ui.AbstractComponent)4