Ejemplo n.º 1
0
  /**
   * Set the current entity that we are browsing and whether the user should be warned or not
   *
   * @param entity
   * @param type
   * @param silent
   */
  private void setEntity(ITridas entity, Class<? extends ITridas> type, Boolean silent) {
    if (!silent) {
      if (!warnLosingChanges()) {
        return;
      }
    }

    hasChanged = false;

    currentEntityType = type;
    currentEntity = entity;

    // Swapping entities so disable editing
    this.enableEditing(false);

    // derive a property list
    List<TridasEntityProperty> properties = TridasEntityDeriver.buildDerivationList(type);
    Property[] propArray = properties.toArray(new Property[properties.size()]);

    // set properties and load from entity
    propertiesPanel.setProperties(propArray);
    propertiesTable.expandAllBranches(true);

    // Add data to table from entity
    if (entity != null) {
      propertiesPanel.readFromObject(entity);
      propertiesPanel.setEnabled(true);
      editEntity.setVisible(true);
    } else {
      propertiesPanel.setEnabled(false);
      editEntity.setVisible(false);
    }
  }
Ejemplo n.º 2
0
  /**
   * Called to enable editing Responsible for loading the duplicate copy into the editor
   *
   * @param enable
   */
  @SuppressWarnings("unchecked")
  protected void enableEditing(boolean enable) {

    propertiesTable.setEditable(enable);

    // show/hide our buttons
    editEntitySave.setEnabled(true);
    editEntityCancel.setEnabled(true);
    editEntitySave.setVisible(enable);
    editEntityCancel.setVisible(enable);

    if (currentEntity == null) {
      editEntityText.setText(null);
    } else {
      editEntityText.setFont(editEntityText.getFont().deriveFont(Font.BOLD));
      editEntityText.setText(
          enable
              ? I18n.getText("metadata.currentlyEditingThis")
                  + " "
                  + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase()
              : I18n.getText("metadata.clickLockToEdit")
                  + " "
                  + TridasTreeViewPanel.getFriendlyClassName(currentEntityType).toLowerCase());
    }
    editEntity.setSelected(enable);

    if (enable) {
      if (currentEntity == null) return;

      if (currentEntity instanceof ITridasSeries)
        temporaryEditingEntity =
            TridasCloner.cloneSeriesRefValues(
                (ITridasSeries) currentEntity,
                (Class<? extends ITridasSeries>) currentEntity.getClass());
      else temporaryEditingEntity = TridasCloner.clone(currentEntity, currentEntity.getClass());

      if (temporaryEditingEntity != null) propertiesPanel.readFromObject(temporaryEditingEntity);
    } else {
      temporaryEditingEntity = null;

      // don't display anything if we have nothingk!
      if (currentEntity != null) {
        propertiesPanel.readFromObject(currentEntity);
      } else {
        return;
      }
    }
  }