Beispiel #1
0
/**
 * <code>GroupEditor</code> TODO DOCUMENT ME
 *
 * @version $Id: GroupEditor.java,v 1.30 2010/04/15 09:55:22 PhilippBouillon Exp $
 */
public class GroupEditor extends AbstractTabEditor {
  protected final transient ILocalConstants constants = Resources.getInstance().getConstants();
  protected final transient ILocalMessages messages = Resources.getInstance().getMessages();

  final AdminController adminController;
  boolean needsUpdate = false;

  public GroupEditor(AdminController adminController) {
    this.adminController = adminController;
  }

  public boolean needsUpdate() {
    return needsUpdate;
  }

  public void clearNeedsUpdate() {
    needsUpdate = false;
  }

  public final EditorTab[] getEditorTabs() {
    return new EditorTab[] {
      new GroupPropertiesTab(this), new GroupMembersTab(this), new GroupRolesTab(this)
    };
  }

  public String getTitle(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      String name = group.getName();
      if (name != null && !name.equals("")) return messages.group(name);
    }
    return constants.newGroup();
  }

  public String getId() {
    // TODO Auto-generated method stub
    return null;
  }

  protected final int getSaveType() {
    return WPaloEvent.SAVED_GROUP_ITEM;
  }

  public void setTextCursor() {
    ((GroupPropertiesTab) tabFolder.getItem(0)).name.focus();
  }
}
/**
 * <code>ViewImporter</code> TODO DOCUMENT ME
 *
 * @version $Id: ViewImportDialog.java,v 1.17 2010/04/12 11:13:36 PhilippBouillon Exp $
 */
public class ViewImportDialog extends Window {
  protected final transient ILocalConstants constants = Resources.getInstance().getConstants();
  protected final transient ILocalMessages messages = Resources.getInstance().getMessages();

  public static final String XOBJECT_TYPE = "viewimporterobject";

  public static final String BUTTON_OK = "apply";
  public static final String BUTTON_CANCEL = "cancel";

  private ViewSelectionTree selectionTree;
  private AccountComboBox accounts;
  private CheckBox makePublicView;
  private CheckBox makeEditableView;

  private Button okButton;
  private Button cancelButton;
  private final boolean importViews;
  private final boolean showBoxes;

  public ViewImportDialog(boolean importViews, boolean showBoxes) {
    this.importViews = importViews;
    this.showBoxes = showBoxes;
    setClosable(false);
    setCloseAction(CloseAction.CLOSE);
    if (importViews) setHeading(constants.selectViewsToImport());
    else setHeading(constants.selectCubesToCreateView());
    setPixelSize(420, showBoxes ? 384 : 344);
    setModal(true);
    add(createForm());
    DOM.setStyleAttribute(getElement(), "backgroundColor", "white");
    initEventHandling();
  }

  public final void addButtonListener(String buttonId, Listener<BaseEvent> listener) {
    if (buttonId.equals(BUTTON_OK)) okButton.addListener(Events.Select, listener);
    else if (buttonId.equals(BUTTON_CANCEL)) cancelButton.addListener(Events.Select, listener);
  }

  public void show() {
    String sessionId = ((Workbench) Registry.get(Workbench.ID)).getUser().getSessionId();
    WPaloServiceProvider.getInstance()
        .loadAccounts(
            sessionId,
            new Callback<XAccount[]>(constants.failedToLoadAccountInformation()) {
              public void onSuccess(XAccount[] xAccounts) {
                accounts.setInput(xAccounts);
                ViewImportDialog.super.show();
              }
            });
  }

  public final XView[] getSelectedViews() {
    return selectionTree.getSelectedViews(isPublic(), isEditable());
  }

  private FormPanel createForm() {
    FormPanel panel = new FormPanel();
    panel.setFrame(true);
    // panel.setIconStyle("icon-filter");
    panel.setCollapsible(false);
    panel.setHeaderVisible(false);
    // panel.setHeading("Select views to import");
    panel.setSize(410, -1);
    panel.setButtonAlign(HorizontalAlignment.RIGHT);
    panel.setLayout(new FlowLayout());

    // main container:
    LayoutContainer main = new LayoutContainer();
    RowLayout rowLayout = new RowLayout();
    main.setLayout(rowLayout);

    main.add(createAccountChoice());
    main.add(createTreePanel());

    panel.add(main);

    // Checkboxes for public/editable:
    final LayoutContainer rights = new LayoutContainer();
    RowLayout rLayout = new RowLayout();
    rights.setLayout(rLayout);

    makePublicView = new CheckBox();
    makePublicView.setBoxLabel(constants.visibleForAllViewers());

    makeEditableView = new CheckBox();
    makeEditableView.setBoxLabel(constants.visibleAndEditableForAllEditors());

    if (showBoxes) {
      rights.add(makePublicView);
      rights.add(makeEditableView);
      makePublicView.setValue(false);
      makeEditableView.setValue(false);
    }
    panel.add(rights);

    LabelField label = new LabelField();
    label.setHeight("20px");
    panel.add(label);

    // finally the apply/cancel button:
    SelectionListener<ComponentEvent> listener =
        new SelectionListener<ComponentEvent>() {
          public void componentSelected(ComponentEvent ce) {
            if (ce.component instanceof Button) {
              Button pressedButton = (Button) ce.component;
              // we close dialog on button press:
              if (closeAction == CloseAction.CLOSE) close(pressedButton);
              else hide(pressedButton);
            }
          }
        };
    okButton = importViews ? new Button(constants.importAction()) : new Button(constants.create());
    okButton.setItemId(BUTTON_OK);
    cancelButton = new Button(constants.cancel());
    cancelButton.setItemId(BUTTON_CANCEL);
    okButton.addSelectionListener(listener);
    cancelButton.addSelectionListener(listener);
    panel.addButton(okButton);
    panel.addButton(cancelButton);

    return panel;
  }

  private final LayoutContainer createAccountPanel() {
    LayoutContainer panel = new LayoutContainer();
    FormLayout layout = new FormLayout();
    layout.setLabelAlign(LabelAlign.LEFT);
    layout.setPadding(0);
    layout.setLabelWidth(80);
    panel.setLayout(layout);
    FormData formData = new FormData("100%");

    // add alias field editor;
    accounts = new AccountComboBox(constants.account(), constants.lowerCaseAccount());
    //				"Account");
    ComboBox<XObjectModel> accountsCombo = accounts.getComboBox();
    panel.add(accountsCombo, formData);

    return panel;
  }

  private final LayoutContainer createTreePanel() {
    LayoutContainer panel = new LayoutContainer();
    panel.setLayout(new RowLayout());
    panel.add(new LabelField(constants.views() + ":"));
    LayoutContainer treePanel = new LayoutContainer();
    selectionTree = new ViewSelectionTree(importViews, false);
    Tree viewTree = selectionTree.getTree();
    viewTree.setCheckable(true);
    //		treePanel.setSize(210, 200);
    treePanel.setWidth("100%");
    treePanel.setHeight(200);
    treePanel.setBorders(true);
    treePanel.setScrollMode(Scroll.AUTOY);
    treePanel.setStyleAttribute("backgroundColor", "white");
    treePanel.add(viewTree);
    panel.add(treePanel);
    return panel;
  }

  private final LayoutContainer createAccountChoice() {
    LayoutContainer panel = new LayoutContainer();
    panel.setLayout(new FillLayout());
    panel.add(createAccountPanel());
    panel.setHeight(30);
    return panel;
  }

  private final void initEventHandling() {
    accounts.addSelectionChangedListener(
        new SelectionChangedListener<XObjectModel>() {
          public void selectionChanged(SelectionChangedEvent<XObjectModel> se) {
            XObjectModel selection = se.getSelectedItem();
            selectionTree.setInput((XAccount) selection.getXObject());
          }
        });
  }

  public boolean isPublic() {
    return makePublicView.getValue();
  }

  public boolean isEditable() {
    return makeEditableView.getValue();
  }
}
Beispiel #3
0
class GroupMembersTab extends EditorTab {
  protected static final transient ILocalConstants constants =
      Resources.getInstance().getConstants();

  private static final String MEMBER_DATA = "com.tensegity.wpalo.groupeditor.memberstab";
  // properties:
  private Table membersTable;
  private final IEditor editor;

  public GroupMembersTab(final IEditor editor) {
    super(constants.members());
    this.editor = editor;
    setText(constants.members());
    setIconStyle("icon-user");
    setClosable(false);

    // create groups table
    List<TableColumn> columns = new ArrayList<TableColumn>();
    TableColumn cbox = new CheckBoxTableColumn("mem_check");
    columns.add(cbox);
    TableColumn col = new TableColumn("User", constants.user(), 200);
    col.setMinWidth(75);
    col.setMaxWidth(400);
    columns.add(col);

    TableColumnModel cm = new TableColumnModel(columns);

    membersTable = new Table(cm);
    membersTable.setSelectionMode(SelectionMode.SINGLE);
    membersTable.setHorizontalScroll(true);
    // disable to allow CheckBox widget!
    membersTable.setBulkRender(false);
    membersTable.setAutoHeight(true);

    membersTable.addTableListener(
        new TableListener() {
          public void tableCellClick(TableEvent te) {
            editor.markDirty();
          }
        });

    add(membersTable);
  }

  public final boolean save(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      group.clearUsers();
      if (group.getId() == null) {
        ((GroupEditor) editor).needsUpdate = true;
        return true;
      }
      for (XUser user : getAllUsers()) {
        if (isSelected(user)) {
          group.addUserID(user.getId());
          user.addGroupID(group.getId());
        } else {
          group.removeUserID(user.getId());
          user.removeGroupID(group.getId());
        }
        ((GroupEditor) editor).adminController.updateUser(user);
      }
    }
    return true;
  }

  public void saveAs(String name, XObject input) {}

  public void set(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      membersTable.removeAll();
      List<String> userIDs = Arrays.asList(group.getUserIDs());
      setUsers(userIDs);
    }
  }

  private final void setUsers(final List<String> userIDs) {
    Workbench wb = (Workbench) Registry.get(Workbench.ID);
    // XUser admin = wb.getUser();
    // if (admin != null) {
    WPaloAdminServiceProvider.getInstance()
        .getUsers(
            wb.getUser().getSessionId(),
            new Callback<XUser[]>(constants.loadingAllUsersFailed()) {
              public void onSuccess(XUser[] users) {
                for (XUser user : users) {
                  boolean check = userIDs.contains(user.getId());
                  TableItem item = new TableItem(new Object[] {check, user.getLogin()});
                  item.setData(MEMBER_DATA, user);
                  membersTable.add(item);
                }
              }
            });
    // }
  }

  private final XUser[] getAllUsers() {
    List<XUser> users = new ArrayList<XUser>();
    for (TableItem item : membersTable.getItems()) {
      users.add((XUser) item.getData(MEMBER_DATA));
    }
    return users.toArray(new XUser[0]);
  }

  private final boolean isSelected(XUser user) {
    for (TableItem item : membersTable.getItems()) {
      XUser xu = (XUser) item.getData(MEMBER_DATA);
      if (xu.equals(user)) {
        boolean selected = false;
        Object colVal = item.getValue(0);
        if (colVal instanceof CheckBox) selected = ((CheckBox) colVal).getValue();
        else if (colVal instanceof Boolean) selected = ((Boolean) colVal).booleanValue();
        return selected;
      }
    }
    return false;
  }
}
Beispiel #4
0
class GroupRolesTab extends EditorTab {
  protected static final transient ILocalConstants constants =
      Resources.getInstance().getConstants();

  private static final String ROLE_DATA = "com.tensegity.wpalo.groupeditor.rolestab";
  // properties:
  private Table rolesTable;

  GroupRolesTab(final IEditor editor) {
    super(constants.roles());
    setText(constants.roles());
    setIconStyle("icon-role2");
    setClosable(false);

    // create roles table
    List<TableColumn> columns = new ArrayList<TableColumn>();
    TableColumn cbox = new CheckBoxTableColumn("role_check");
    columns.add(cbox);
    TableColumn col = new TableColumn("Role", constants.role(), 150);
    col.setMinWidth(75);
    col.setMaxWidth(300);
    columns.add(col);
    col = new TableColumn("Right", constants.right(), 100);
    col.setAlignment(HorizontalAlignment.LEFT);
    columns.add(col);
    col = new TableColumn("Description", constants.description(), 800);
    col.setMaxWidth(800);
    col.setAlignment(HorizontalAlignment.LEFT);
    columns.add(col);

    TableColumnModel cm = new TableColumnModel(columns);

    rolesTable = new Table(cm);
    rolesTable.setSelectionMode(SelectionMode.MULTI);
    rolesTable.setHorizontalScroll(true);
    rolesTable.setBulkRender(false);
    rolesTable.setAutoHeight(true);

    rolesTable.addTableListener(
        new TableListener() {
          public void tableCellClick(TableEvent te) {
            editor.markDirty();
          }
        });

    add(rolesTable);
  }

  public final boolean save(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      group.clearRoles();
      for (XRole role : getSelectedRoles()) group.addRoleID(role.getId());
    }
    return true;
  }

  public void saveAs(String name, XObject input) {}

  public void set(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      rolesTable.removeAll();
      boolean isAdm = group != null && group.getName() != null && group.getName().equals("admin");
      ((CheckBoxTableColumn) rolesTable.getColumnModel().getColumn(0)).setEnabled(!isAdm);
      List<String> roleIDs = Arrays.asList(group.getRoleIDs());
      setRoles(roleIDs);
    }
  }

  private final String translateDescription(String s) {
    if (s == null) {
      return null;
    }
    if (s.equals(
        "Grants the right to view & edit administration area and modify & share all existing views (System)")) {
      return constants.grantAdmin();
    } else if (s.equals("Grants the right to share views created by this user")) {
      return constants.grantShare();
    } else if (s.equals("Grants the right to modify views shared by other users (System)")) {
      return constants.grantModify();
    } else if (s.equals("Grants the right to create and modify own views")) {
      return constants.grantCreate();
    } else if (s.equals("Grants the right to see views shared by other users (System)")) {
      return constants.grantView();
    } else if (s.equals("Grants the right to create views and edit these views (System)")) {
      return constants.grantCreateEdit();
    } else if (s.equals("Grants the right to create, modify and publish own views")) {
      return constants.grantPublish();
    }
    return s;
  }

  private final void setRoles(final List<String> roleIDs) {
    Workbench wb = (Workbench) Registry.get(Workbench.ID);
    XUser admin = wb.getUser();
    if (admin != null) {
      WPaloAdminServiceProvider.getInstance()
          .getRoles(
              admin.getSessionId(),
              admin,
              new Callback<XRole[]>(constants.loadingAllRolesFailed()) {
                public void onSuccess(XRole[] roles) {
                  for (XRole role : roles) {
                    boolean check = roleIDs.contains(role.getId());
                    String rightName = constants.none();
                    String p = role.getPermission();
                    if (p.equals("R")) rightName = constants.read();
                    else if (p.equals("W")) rightName = constants.write();
                    else if (p.equals("D")) rightName = constants.delete();
                    else if (p.equals("C")) rightName = constants.create();
                    else if (p.equals("G")) rightName = constants.grant();
                    TableItem item =
                        new TableItem(
                            new Object[] {
                              check, role.getName(),
                              rightName, translateDescription(role.getDescription())
                            });
                    item.setData(ROLE_DATA, role);
                    rolesTable.add(item);
                  }
                }
              });
    }
  }

  private final XRole[] getSelectedRoles() {
    // collect all selected roles:
    List<XRole> roles = new ArrayList<XRole>();
    for (TableItem item : rolesTable.getItems()) {
      boolean selected = false;
      Object colVal = item.getValue(0);
      if (colVal instanceof CheckBox) selected = ((CheckBox) colVal).getValue();
      else if (colVal instanceof Boolean) selected = ((Boolean) colVal).booleanValue();
      if (selected) roles.add((XRole) item.getData(ROLE_DATA));
    }
    return roles.toArray(new XRole[0]);
  }
}
Beispiel #5
0
class GroupPropertiesTab extends EditorTab {
  protected static final transient ILocalConstants constants =
      Resources.getInstance().getConstants();

  // properties:
  TextField<String> name;
  private TextArea description;
  private IEditor editor;

  GroupPropertiesTab(IEditor editor) {
    super(constants.general());
    this.editor = editor;
    setText(constants.general());
    setIconStyle("icon-group");
    setClosable(false);
    setScrollMode(Scroll.AUTO);
    add(createPropertiesContent());
  }

  public final boolean save(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      group.setName(name.getValue());
      group.setDescription(description.getValue());
    }
    return true;
  }

  public void saveAs(String name, XObject input) {}

  private final String translateDescription(String s) {
    if (s == null) {
      return null;
    }
    if (s.equals(
        "Grants the right to view & edit administration area and modify & share all existing views (System)")) {
      return constants.grantAdmin();
    } else if (s.equals("Grants the right to share views created by this user")) {
      return constants.grantShare();
    } else if (s.equals("Grants the right to modify views shared by other users (System)")) {
      return constants.grantModify();
    } else if (s.equals("Grants the right to create and modify own views")) {
      return constants.grantCreate();
    } else if (s.equals("Grants the right to see views shared by other users (System)")) {
      return constants.grantView();
    } else if (s.equals("Grants the right to create views and edit these views (System)")) {
      return constants.grantCreateEdit();
    } else if (s.equals("Grants the right to create, modify and publish own views")) {
      return constants.grantPublish();
    }
    return s;
  }

  public void set(XObject input) {
    if (input instanceof XGroup) {
      XGroup group = (XGroup) input;
      name.setValue(group.getName());
      description.setValue(translateDescription(group.getDescription()));
      if (group != null
          && group.getName() != null
          && (group.getName().equals("admin")
              || group.getName().equals("editor")
              || group.getName().equals("creator")
              || group.getName().equals("viewer")
              || group.getName().equals("poweruser")
              || group.getName().equals("publisher"))) {
        name.setEnabled(false);
        description.setEnabled(false);
      } else {
        name.setEnabled(true);
        description.setEnabled(true);
      }
    }
  }

  private final ContentPanel createPropertiesContent() {
    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(false);
    panel.setButtonAlign(HorizontalAlignment.RIGHT);
    panel.setStyleAttribute("padding", "20");

    KeyListener keyListener =
        new KeyListener() {
          public void componentKeyUp(ComponentEvent event) {
            editor.markDirty();
          }
        };

    name = new TextField<String>();
    name.setFieldLabel(constants.name());
    name.setEmptyText(constants.groupName());
    name.setAllowBlank(false);
    name.setMinLength(2);
    name.addKeyListener(keyListener);
    name.setStyleAttribute("marginTop", "5");
    name.setStyleAttribute("marginBottom", "5");
    panel.add(name);

    description = new TextArea();
    description.setPreventScrollbars(true);
    description.setFieldLabel(constants.description());
    description.addKeyListener(keyListener);
    description.setStyleAttribute("marginTop", "5");
    description.setStyleAttribute("marginBottom", "5");
    panel.add(description);

    return panel;
  }
}