private Widget createValuePairItem(
      final Annotation annotation,
      final AnnotationValuePairDefinition valuePairDefinition,
      final AnnotationSource annotationSource) {
    final Row valuePairRow = new Row();
    final FormGroup formGroup = new FormGroup();
    valuePairRow.add(formGroup);

    final FormLabel formLabel = new FormLabel();
    formLabel.addStyleName(ColumnSize.MD_3.getCssName());
    formLabel.setText(valuePairDefinition.getName());
    formGroup.add(formLabel);

    final Column column = new Column(ColumnSize.MD_9);
    formGroup.add(column);
    final TextBox content = new TextBox();
    column.add(content);
    final String valuePairString =
        getValuePairStringValue(annotation, valuePairDefinition, annotationSource);
    content.setText(valuePairString);
    content.setReadOnly(true);
    content.setTitle(valuePairString);

    final Button editButton =
        new Button(
            Constants.INSTANCE.advanced_domain_annotation_list_editor_action_edit(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                presenter.onEditValuePair(annotation, valuePairDefinition.getName());
              }
            });
    editButton.setEnabled(!readonly);
    editButton.setIcon(IconType.EDIT);

    final Button clearButton =
        new Button(
            Constants.INSTANCE.advanced_domain_annotation_list_editor_action_clear(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                presenter.onClearValuePair(annotation, valuePairDefinition.getName());
              }
            });
    clearButton.setEnabled(!readonly);
    clearButton.setIcon(IconType.ERASER);

    final FormGroup formGroupButton = new FormGroup();
    formGroupButton.add(editButton);
    formGroupButton.add(clearButton);
    final Column columnButton = new Column(ColumnSize.MD_9);
    columnButton.setOffset(ColumnOffset.MD_3);
    columnButton.add(formGroupButton);
    valuePairRow.add(columnButton);

    return valuePairRow;
  }
  private void addRemoveRowColumn() {
    Column<PropertyRow, String> column =
        new Column<PropertyRow, String>(
            new ButtonCell(IconType.TRASH, ButtonType.DANGER, ButtonSize.SMALL)) {
          @Override
          public String getValue(PropertyRow propertyRow) {
            return Constants.INSTANCE.persistence_unit_property_grid_action_delete();
          }
        };

    column.setFieldUpdater(
        new FieldUpdater<PropertyRow, String>() {
          @Override
          public void update(int index, PropertyRow propertyRow, String value) {

            if (!readOnly) {
              onRemoveProperty(propertyRow);
            }
          }
        });

    dataGrid.addColumn(
        column, Constants.INSTANCE.persistence_unit_property_grid_property_action_column());
    dataGrid.setColumnWidth(column, 10, Style.Unit.PCT);
  }
 protected void rename() {
   if (isDirty()) {
     YesNoCancelPopup yesNoCancelPopup =
         YesNoCancelPopup.newYesNoCancelPopup(
             CommonConstants.INSTANCE.Information(),
             Constants.INSTANCE.modelEditor_confirm_save_before_rename(),
             new Command() {
               @Override
               public void execute() {
                 rename(true);
               }
             },
             new Command() {
               @Override
               public void execute() {
                 rename(false);
               }
             },
             new Command() {
               @Override
               public void execute() {
                 // do nothing.
               }
             });
     yesNoCancelPopup.setClosable(false);
     yesNoCancelPopup.show();
   } else {
     // just rename.
     rename(false);
   }
 }
  @Override
  public void onSourceTabSelected() {

    context.setEditionMode(DataModelerContext.EditionMode.SOURCE_MODE);
    if (context.isParsed() && context.isEditorChanged()) {

      // If there are changes in the ui the source must be regenerated on server side.
      view.showLoading();
      modelerService
          .call(
              new RemoteCallback<GenerationResult>() {
                @Override
                public void callback(GenerationResult result) {
                  view.hideBusyIndicator();
                  setSource(result.getSource());
                  updateSource(result.getSource());
                  context.setEditionStatus(DataModelerContext.EditionStatus.NO_CHANGES);
                  dataModelerWBContext.setActiveContext(context);
                }
              },
              new DataModelerErrorCallback(Constants.INSTANCE.modelEditor_loading_error()))
          .updateSource(
              getSource(), versionRecordManager.getCurrentPath(), context.getDataObject());
    } else {
      if (!isOverviewTabSelected()) {
        context.setEditionStatus(DataModelerContext.EditionStatus.NO_CHANGES);
      }
      updateSource(javaSourceEditor.getContent());
      dataModelerWBContext.setActiveContext(context);
    }
  }
  private void onDataObjectDeleted(@Observes DataObjectDeletedEvent event) {
    if (context != null
        && event.isFrom(context.getCurrentProject())
        && event.getCurrentDataObject() != null
        && context.isParsed()
        && isEditorTabSelected()
        && context.getDataObject() != null
        && !context
            .getDataObject()
            .getClassName()
            .equals(event.getCurrentDataObject().getClassName())) {

      // check deleted object is referenced by current data object.
      if (validatorService.isReferencedByCurrentObject(
          event.getCurrentDataObject(), context.getDataObject())) {
        notification.fire(
            new NotificationEvent(
                Constants.INSTANCE.modelEditor_notification_dataObject_referenced_has_been_deleted(
                    event.getCurrentDataObject().getClassName(),
                    context.getDataObject().getClassName())));
      } else if (!getDataModel().isExternal(event.getCurrentDataObject().getClassName())) {
        getDataModel().removeDataObject(event.getCurrentDataObject().getClassName());
        view.refreshTypeLists(true);
      }
    }
  }
  public PersistenceUnitPropertyGridViewImpl() {

    initWidget(uiBinder.createAndBindUi(this));

    dataGrid.setEmptyTableCaption(
        Constants.INSTANCE.persistence_unit_property_grid_no_properties_message());
    dataGrid.setToolBarVisible(false);

    addPropertyNameColumn();
    addPropertyValueColumn();
    addRemoveRowColumn();
  }
  private String getValuePairStringValue(
      Annotation annotation,
      AnnotationValuePairDefinition valuePairDefinition,
      AnnotationSource annotationSource) {

    Object value = annotation.getValue(valuePairDefinition.getName());
    String strValue;

    if (value == null) {
      strValue = Constants.INSTANCE.advanced_domain_annotation_list_editor_message_value_not_set();
    } else {
      strValue =
          annotationSource != null
              ? annotationSource.getValuePairSource(valuePairDefinition.getName())
              : null;
      if (strValue == null) {
        strValue =
            Constants.INSTANCE
                .advanced_domain_annotation_list_editor_message_source_code_not_available();
      }
    }

    return strValue;
  }
  private void initContext(final ObservablePath path) {
    context = new DataModelerContext(editorId);

    modelerService
        .call(
            new RemoteCallback<List<PropertyType>>() {
              @Override
              public void callback(List<PropertyType> baseTypes) {
                context.init(baseTypes);
              }
            },
            new DataModelerErrorCallback(
                Constants.INSTANCE.modelEditor_propertyType_loading_error()))
        .getBasePropertyTypes();
  }
Ejemplo n.º 9
0
  private String propertyTypeDisplay(ObjectProperty property) {
    String displayName = property.getClassName();

    if (property.isBaseType()) {
      displayName = DataModelerUtils.extractClassName(displayName);
    } else {
      String label = getContext().getHelper().getObjectLabelByClassName(displayName);
      if (label != null && !"".equals(label)) {
        displayName = label;
      }
    }

    if (property.isMultiple()) {
      displayName += " [" + Constants.INSTANCE.objectBrowser_typeLabelMultiple() + "]";
    }
    return displayName;
  }
  private void addPropertyNameColumn() {
    Column<PropertyRow, String> column =
        new Column<PropertyRow, String>(new EditTextCell()) {
          @Override
          public String getValue(PropertyRow propertyRow) {
            if (propertyRow.getName() != null) {
              return propertyRow.getName();
            } else {
              return "";
            }
          }
        };

    column.setFieldUpdater(
        new PropertyNameFieldUpdater<PropertyRow, String>((EditTextCell) column.getCell()));

    dataGrid.addColumn(
        column, Constants.INSTANCE.persistence_unit_property_grid_property_name_column());
    dataGrid.setColumnWidth(column, 45, Style.Unit.PCT);
  }
  @Override
  protected void loadContent() {

    modelerService
        .call(
            new RemoteCallback<Map<String, AnnotationDefinition>>() {
              @Override
              public void callback(final Map<String, AnnotationDefinition> defs) {

                context.setAnnotationDefinitions(defs);

                modelerService
                    .call(getLoadModelSuccessCallback(), getNoSuchFileExceptionErrorCallback())
                    .loadContent(versionRecordManager.getCurrentPath());
              }
            },
            new DataModelerErrorCallback(
                Constants.INSTANCE.modelEditor_annotationDef_loading_error()))
        .getAnnotationDefinitions();
  }
Ejemplo n.º 12
0
  public DataObjectBrowser() {
    initWidget(uiBinder.createAndBindUi(this));

    objectButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            selectCurrentObject(true);
          }
        });

    dataObjectPropertiesProvider.setList(new ArrayList<ObjectProperty>());

    // Init data objects table

    dataObjectPropertiesTable.setEmptyTableWidget(
        new Label(Constants.INSTANCE.objectBrowser_emptyTable()));

    // Init property name column

    final TextColumn<ObjectProperty> propertyNameColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return objectProperty.getName();
          }
        };

    propertyNameColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyNameColumn, Constants.INSTANCE.objectBrowser_columnName());
    // dataObjectPropertiesTable.setColumnWidth(propertyNameColumn, 100, Style.Unit.PX);
    dataObjectPropertiesTable.setColumnWidth(propertyNameColumn, 30, Style.Unit.PCT);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyNameColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyNameColHandler.setComparator(propertyNameColumn, new ObjectPropertyComparator("name"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyNameColHandler);

    // Init property Label column

    final TextColumn<ObjectProperty> propertyLabelColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return AnnotationValueHandler.getStringValue(
                objectProperty,
                MainDomainAnnotations.LABEL_ANNOTATION,
                MainDomainAnnotations.VALUE_PARAM);
          }
        };

    propertyLabelColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyLabelColumn, Constants.INSTANCE.objectBrowser_columnLabel());
    dataObjectPropertiesTable.setColumnWidth(propertyLabelColumn, 30, Style.Unit.PCT);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyLabelColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyNameColHandler.setComparator(
        propertyLabelColumn, new ObjectPropertyComparator("label"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyLabelColHandler);

    // Init property type browsing column
    ClickableImageResourceCell typeImageCell = new ClickableImageResourceCell(true, 25);
    //        final TooltipCellDecorator<ImageResource> typeImageDecorator = new
    // TooltipCellDecorator<ImageResource>( typeImageCell );
    //        typeImageDecorator.setText(
    // Constants.INSTANCE.objectBrowser_action_goToDataObjectDefinition() );

    final Column<ObjectProperty, ImageResource> typeImageColumn =
        new Column<ObjectProperty, ImageResource>(typeImageCell) {
          @Override
          public ImageResource getValue(final ObjectProperty property) {

            if (!property.isBaseType()
                && !getDataObject().getClassName().equals(property.getClassName())
                && !getDataModel().isExternal(property.getClassName())) {
              return ImagesResources.INSTANCE.BrowseObject();
            } else {
              return null;
            }
          }
        };

    typeImageColumn.setFieldUpdater(
        new FieldUpdater<ObjectProperty, ImageResource>() {
          public void update(
              final int index, final ObjectProperty property, final ImageResource value) {

            onTypeCellSelection(property);
          }
        });

    dataObjectPropertiesTable.addColumn(typeImageColumn);

    // Init property type column
    final TextColumn<ObjectProperty> propertyTypeColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return propertyTypeDisplay(objectProperty);
          }
        };
    propertyTypeColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyTypeColumn, Constants.INSTANCE.objectBrowser_columnType());
    dataObjectPropertiesTable.setColumnWidth(propertyTypeColumn, 40, Style.Unit.PCT);

    // Init delete column
    final Column<ObjectProperty, String> deletePropertyColumnImg =
        new Column<ObjectProperty, String>(deleteCell) {
          @Override
          public String getValue(final ObjectProperty global) {
            return "Remove";
          }
        };

    deletePropertyColumnImg.setFieldUpdater(
        new FieldUpdater<ObjectProperty, String>() {
          public void update(final int index, final ObjectProperty property, final String value) {
            if (!isReadonly()) {
              checkAndDeleteDataObjectProperty(property, index);
            }
          }
        });

    dataObjectPropertiesTable.addColumn(deletePropertyColumnImg);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyTypeColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyTypeColHandler.setComparator(
        propertyTypeColumn, new ObjectPropertyComparator("className"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyTypeColHandler);

    dataObjectPropertiesTable.getColumnSortList().push(propertyNameColumn);

    // Init the selection model
    SingleSelectionModel<ObjectProperty> selectionModel =
        new SingleSelectionModel<ObjectProperty>();
    dataObjectPropertiesTable.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {

          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            ObjectProperty selectedProperty =
                ((SingleSelectionModel<ObjectProperty>)
                        dataObjectPropertiesTable.getSelectionModel())
                    .getSelectedObject();
            notifyFieldSelected(selectedProperty);
          }
        });

    dataObjectPropertiesTable.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.BOUND_TO_SELECTION);

    dataObjectPropertiesTable.addCellPreviewHandler(
        new CellPreviewEvent.Handler<ObjectProperty>() {

          @Override
          public void onCellPreview(CellPreviewEvent<ObjectProperty> event) {
            if (showingObject && "click".equals(event.getNativeEvent().getType())) {
              int selectedRow = dataObjectPropertiesTable.getKeyboardSelectedRow();
              if (lastSelectedRow >= 0 && lastSelectedRow == selectedRow) {
                ObjectProperty selectedProperty =
                    dataObjectPropertiesProvider.getList().get(selectedRow);
                ((SingleSelectionModel<ObjectProperty>)
                        dataObjectPropertiesTable.getSelectionModel())
                    .setSelected(selectedProperty, true);
              }
              showingObject = false;
            }
          }
        });

    dataObjectPropertiesProvider.addDataDisplay(dataObjectPropertiesTable);
    dataObjectPropertiesProvider.refresh();

    newPropertyButton.setIcon(IconType.PLUS);

    setReadonly(true);
  }
  private void saveFile(final JavaTypeInfo newTypeInfo) {

    String currentFileName =
        DataModelerUtils.extractSimpleFileName(versionRecordManager.getPathToLatest());

    if (hasPackageNameChanged(newTypeInfo)) {

      YesNoCancelPopup yesNoCancelPopup =
          YesNoCancelPopup.newYesNoCancelPopup(
              CommonConstants.INSTANCE.Information(),
              Constants.INSTANCE.modelEditor_confirm_file_package_refactoring(
                  newTypeInfo.getPackageName()),
              new Command() {
                @Override
                public void execute() {
                  saveOperationService.save(
                      versionRecordManager.getPathToLatest(),
                      getSaveCommand(newTypeInfo, versionRecordManager.getPathToLatest()));
                }
              },
              Constants.INSTANCE.modelEditor_action_yes_refactor_directory(),
              ButtonType.PRIMARY,
              new Command() {
                @Override
                public void execute() {
                  saveOperationService.save(
                      versionRecordManager.getPathToLatest(),
                      getSaveCommand(null, versionRecordManager.getPathToLatest()));
                }
              },
              Constants.INSTANCE.modelEditor_action_no_dont_refactor_directory(),
              ButtonType.DANGER,
              new Command() {
                @Override
                public void execute() {
                  // do nothing
                }
              },
              null,
              null);

      yesNoCancelPopup.setClosable(false);
      yesNoCancelPopup.show();

    } else if (hasFileNameChanged(newTypeInfo, currentFileName)) {

      YesNoCancelPopup yesNoCancelPopup =
          YesNoCancelPopup.newYesNoCancelPopup(
              CommonConstants.INSTANCE.Information(),
              Constants.INSTANCE.modelEditor_confirm_file_name_refactoring(newTypeInfo.getName()),
              new Command() {
                @Override
                public void execute() {
                  saveOperationService.save(
                      versionRecordManager.getPathToLatest(),
                      getSaveCommand(newTypeInfo, versionRecordManager.getPathToLatest()));
                }
              },
              Constants.INSTANCE.modelEditor_action_yes_refactor_file_name(),
              ButtonType.PRIMARY,
              new Command() {
                @Override
                public void execute() {
                  saveOperationService.save(
                      versionRecordManager.getPathToLatest(),
                      getSaveCommand(null, versionRecordManager.getPathToLatest()));
                }
              },
              Constants.INSTANCE.modelEditor_action_no_dont_refactor_file_name(),
              ButtonType.DANGER,
              new Command() {
                @Override
                public void execute() {
                  // do nothing
                }
              },
              null,
              null);

      yesNoCancelPopup.setClosable(false);
      yesNoCancelPopup.show();

    } else {
      new SaveOperationService()
          .save(
              versionRecordManager.getPathToLatest(),
              getSaveCommand(null, versionRecordManager.getPathToLatest()));
    }
  }
  @Override
  public void onEditTabSelected() {

    boolean doParsing = false;
    if (context.isSourceChanged()) {
      // if there has been changes in the source we should try to parse the file and build the data
      // object again.
      doParsing = true;
    } else if (context.isNotParsed()) {
      // uncommon case, the file wasn't parsed yet.
      doParsing = true;
    }

    if (doParsing) {

      view.showLoading();

      // If there are changes in the source, we must try to parse the file.
      modelerService
          .call(
              new RemoteCallback<GenerationResult>() {
                @Override
                public void callback(GenerationResult result) {
                  view.hideBusyIndicator();

                  if (result.hasErrors()) {

                    showParseErrorsDialog(
                        Constants.INSTANCE.modelEditor_message_file_parsing_errors(),
                        true,
                        result.getErrors(),
                        new Command() {
                          @Override
                          public void execute() {
                            // return to the source tab
                            setSelectedTab(EDITABLE_SOURCE_TAB);
                            context.setParseStatus(DataModelerContext.ParseStatus.PARSE_ERRORS);
                            updateEditorView(null);
                            context.setDataObject(null);
                            context.setEditionMode(DataModelerContext.EditionMode.SOURCE_MODE);
                            dataModelerWBContext.setActiveContext(context);
                          }
                        });

                  } else {
                    // ok, we can reload the editor tab.
                    context.setParseStatus(DataModelerContext.ParseStatus.PARSED);
                    updateEditorView(result.getDataObject());
                    context.setEditionStatus(DataModelerContext.EditionStatus.NO_CHANGES);
                    context.setDataObject(result.getDataObject());
                    context.setObjectProperty(null);
                    context.setEditionMode(DataModelerContext.EditionMode.GRAPHICAL_MODE);
                    view.setContext(context);
                    cleanSystemMessages(getCurrentMessageType());
                    dataModelerWBContext.setActiveContext(context);
                  }
                }
              },
              new DataModelerErrorCallback(Constants.INSTANCE.modelEditor_loading_error()))
          .updateDataObject(
              context.getDataObject(), getSource(), versionRecordManager.getCurrentPath());
    } else {
      // no changes in the source tab
      if (!isOverviewTabSelected()) {
        context.setEditionStatus(DataModelerContext.EditionStatus.NO_CHANGES);
      }

      if (context.isParseErrors()) {
        // there are parse errors, the editor tab couldn't be loaded.  (errors are already
        // published)
        showParseErrorsDialog(
            Constants.INSTANCE.modelEditor_message_file_parsing_errors(),
            false,
            null,
            new Command() {
              @Override
              public void execute() {
                context.setEditionMode(DataModelerContext.EditionMode.SOURCE_MODE);
                dataModelerWBContext.setActiveContext(context);
                setSelectedTab(EDITABLE_SOURCE_TAB);
              }
            });
      } else {
        context.setEditionMode(DataModelerContext.EditionMode.GRAPHICAL_MODE);
        dataModelerWBContext.setActiveContext(context);
      }
    }
  }