예제 #1
0
  protected void mapFromObjects() throws RaplaException {
    classificationField.mapFrom(objectList);
    permissionListField.mapFrom(objectList);
    Set<Boolean> values = new HashSet<Boolean>();
    boolean canAdmin = true;
    boolean allPermissions = true;
    boolean internal = false;
    final User user = getUser();

    for (Allocatable alloc : objectList) {
      if (isInternalType(alloc)) {
        internal = true;
      }
      if (((DynamicTypeImpl) alloc.getClassification().getType()).isInternal()) {
        allPermissions = false;
      }
      String annotation = alloc.getAnnotation(ResourceAnnotations.KEY_CONFLICT_CREATION);
      boolean holdBackConflicts =
          annotation != null
              && annotation.equals(ResourceAnnotations.VALUE_CONFLICT_CREATION_IGNORE);
      values.add(holdBackConflicts);
      if (!permissionController.canAdmin(alloc, user)) {
        canAdmin = false;
      }
    }
    if (canAdmin == false) {
      permissionListField.getComponent().setVisible(false);
    }
    if (allPermissions) {
      permissionListField.setPermissionLevels(
          Permission.DENIED,
          Permission.READ_NO_ALLOCATION,
          Permission.READ,
          Permission.ALLOCATE,
          Permission.ALLOCATE_CONFLICTS,
          Permission.EDIT,
          Permission.ADMIN);
    } else {
      permissionListField.setPermissionLevels(Permission.DENIED, Permission.READ);
    }
    if (internal) {
      holdBackConflictPanel.setVisible(false);
      classificationField.setTypeChooserVisible(false);
    } else {
      if (values.size() == 1) {
        Boolean singleValue = values.iterator().next();
        holdBackConflictsField.setValue(singleValue);
      }
      if (values.size() > 1) {
        holdBackConflictsField.setFieldForMultipleValues();
      }
      holdBackConflictPanel.setVisible(true);
      classificationField.setTypeChooserVisible(true);
    }
  }
예제 #2
0
  @Inject
  public AllocatableEditUI(RaplaContext context) throws RaplaException {
    super(context);
    classificationField = new ClassificationField<Allocatable>(context);
    permissionField = new PermissionListField(context, getString("permissions"));

    permissionField.setPermissionLevels(
        Permission.DENIED,
        Permission.READ_NO_ALLOCATION,
        Permission.READ,
        Permission.ALLOCATE,
        Permission.ALLOCATE_CONFLICTS,
        Permission.EDIT,
        Permission.ADMIN);
    final JComponent permissionPanel = permissionField.getComponent();
    editPanel.setLayout(new BorderLayout());
    editPanel.add(classificationField.getComponent(), BorderLayout.CENTER);
    holdBackConflictsField = new BooleanField(context, getString("holdbackconflicts"));
    holdBackConflictPanel = new JPanel();
    holdBackConflictPanel.setLayout(new BorderLayout());
    holdBackConflictPanel.add(
        new JLabel(holdBackConflictsField.getFieldName() + ": "), BorderLayout.WEST);
    holdBackConflictPanel.add(holdBackConflictsField.getComponent(), BorderLayout.CENTER);

    classificationField.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            final boolean mainTabSelected = classificationField.isMainTabSelected();
            permissionPanel.setVisible(!mainTabSelected);
            if (!mainTabSelected && !editPanel.isAncestorOf(permissionPanel)) {
              editPanel.remove(holdBackConflictPanel);
              editPanel.add(permissionPanel, BorderLayout.SOUTH);
              editPanel.repaint();
            }

            if (mainTabSelected && (!editPanel.isAncestorOf(holdBackConflictPanel))) {
              editPanel.remove(permissionPanel);
              editPanel.add(holdBackConflictPanel, BorderLayout.SOUTH);
              editPanel.repaint();
            }
            AllocatableEditUI.this.stateChanged(e);
          }
        });
    editPanel.setPreferredSize(new Dimension(800, 600));
  }
예제 #3
0
 public void mapToObjects() throws RaplaException {
   classificationField.mapTo(objectList);
   permissionField.mapTo(objectList);
   if (getName(objectList).length() == 0) throw new RaplaException(getString("error.no_name"));
   for (Allocatable alloc : objectList) {
     if (!isInternalType(alloc)) {
       Boolean value = holdBackConflictsField.getValue();
       alloc.setAnnotation(
           ResourceAnnotations.KEY_CONFLICT_CREATION,
           (value != null && value) ? ResourceAnnotations.VALUE_CONFLICT_CREATION_IGNORE : null);
     }
   }
 }
예제 #4
0
  @SuppressWarnings("unchecked")
  @Inject
  public AllocatableEditUI(
      ClientFacade facade,
      RaplaResources i18n,
      RaplaLocale raplaLocale,
      Logger logger,
      ClassificationFieldFactory classificationFieldFactory,
      PermissionListFieldFactory permissionListFieldFactory,
      BooleanFieldFactory booleanFieldFactory)
      throws RaplaInitializationException {
    super(facade, i18n, raplaLocale, logger);
    this.permissionController = facade.getRaplaFacade().getPermissionController();
    classificationField = classificationFieldFactory.create();
    try {
      this.permissionListField = permissionListFieldFactory.create(getString("permissions"));
    } catch (RaplaException e1) {
      throw new RaplaInitializationException(e1);
    }

    this.permissionListField.setPermissionLevels(
        Permission.DENIED,
        Permission.READ_NO_ALLOCATION,
        Permission.READ,
        Permission.ALLOCATE,
        Permission.ALLOCATE_CONFLICTS,
        Permission.EDIT,
        Permission.ADMIN);
    final JComponent permissionPanel = permissionListField.getComponent();
    editPanel.setLayout(new BorderLayout());
    editPanel.add(classificationField.getComponent(), BorderLayout.CENTER);
    holdBackConflictsField = booleanFieldFactory.create(getString("holdbackconflicts"));
    holdBackConflictPanel = new JPanel();
    holdBackConflictPanel.setLayout(new BorderLayout());
    holdBackConflictPanel.add(
        new JLabel(holdBackConflictsField.getFieldName() + ": "), BorderLayout.WEST);
    holdBackConflictPanel.add(holdBackConflictsField.getComponent(), BorderLayout.CENTER);

    classificationField.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent e) {
            final boolean mainTabSelected = classificationField.isMainTabSelected();
            permissionPanel.setVisible(!mainTabSelected);
            if (!mainTabSelected && !editPanel.isAncestorOf(permissionPanel)) {
              editPanel.remove(holdBackConflictPanel);
              editPanel.add(permissionPanel, BorderLayout.SOUTH);
              editPanel.repaint();
            }

            if (mainTabSelected && (!editPanel.isAncestorOf(holdBackConflictPanel))) {
              editPanel.remove(permissionPanel);
              editPanel.add(holdBackConflictPanel, BorderLayout.SOUTH);
              editPanel.repaint();
            }
            AllocatableEditUI.this.stateChanged(e);
          }
        });
    editPanel.setPreferredSize(new Dimension(800, 600));
  }