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();
}
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
}
} });
}
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);
}
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();
}
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;
}
}
Aggregations