Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Can I make table columns "un-hideable"?
Can I make table columns "un-hideable"? [message #1017773] Tue, 12 March 2013 14:06 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Table columns have the "Displayable" property, which I can set to false to keep the user from showing the column using "right mouse click->organise columns".

I am looking for the opposite: I want to set a property that makes it impossible for the user to hide a column using "organise columns". Is this possible?


On a related note: It is possible to fix a column width by setting the ConfiguredFixedWidth property. Is it possible to lock a column position, so it can't be moved in the table?


On another related note: Is it possible to completely suppress the "organise columns" menu for specific tables?
Re: Can I make table columns "un-hideable"? [message #1018169 is a reply to message #1017773] Wed, 13 March 2013 09:52 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
A column:
* Not Displayable => as if it was not there for the end user.
* Displayable => Can be set "Visible" or "Not Visible" (configured by the developer == initial State) or modified during runtime by the user. This configuration made by the user is persisted in the user preferences.

I do not know a mechanism that prevent from reorganizing a table.

The only possibilities I know concerns sorting: it is possible to disable sorting and to have sorting columns before and after the one defined by the user.


It might be possible to modify the menus proposed on table header (create your own table/column extending AbstracTable/AbstractColumn or with the "injection" mechanism) but I am not so sure.
Re: Can I make table columns "un-hideable"? [message #1018280 is a reply to message #1018169] Wed, 13 March 2013 14:55 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks for your answer (even if it confirmed what I had suspected: I want something that can't easily be done Smile
Re: Can I make table columns "un-hideable"? [message #1018797 is a reply to message #1017773] Thu, 14 March 2013 13:38 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
Hi Urs

The organize columns menu is added to the table in AbstractTable#execAddHeaderMenus. To suppress the menus, just override this method and make sure it does nothing.

This is also the point to add a custom OrganizeColumnsMenu with a custom OrganizeColumnsForm which is able to handle your "prevent hiding a column" property.
Re: Can I make table columns "un-hideable"? [message #1020432 is a reply to message #1018797] Mon, 18 March 2013 06:50 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Excellent, thank you. I'll have a look at this.
Re: Can I make table columns "un-hideable"? [message #1021130 is a reply to message #1020432] Tue, 19 March 2013 15:06 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
After some playing, I've managed to solve all of my needs (except for fixing some columns so they can't be dragged to a different position).

In my client I've created the following classes:
org.eclipse.minicrm.client.ui.table.IForceVisible (to allow certain columns to be marked as non-hidable):
package org.eclipse.minicrm.client.ui.table;

public interface IForceVisible {
  public boolean getConfiguredForceVisible();
}


org.eclipse.minicrm.client.ui.table.ReducedMenuTable (a table with a reduced menu (simple reset menu only) and per-column menu for showing/hiding columns)
package org.eclipse.minicrm.client.ui.table;

import org.eclipse.minicrm.client.ui.table.menus.CheckColumnMenu;
import org.eclipse.minicrm.client.ui.table.menus.ReducedResetColumnsMenu;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.action.menu.IMenu;
import org.eclipse.scout.rt.client.ui.action.menu.MenuSeparator;
import org.eclipse.scout.rt.client.ui.basic.table.AbstractTable;
import org.eclipse.scout.rt.client.ui.basic.table.TableEvent;
import org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn;
import org.eclipse.scout.rt.client.ui.basic.table.customizer.AddCustomColumnMenu;
import org.eclipse.scout.rt.client.ui.basic.table.customizer.ModifyCustomColumnMenu;
import org.eclipse.scout.rt.client.ui.basic.table.customizer.RemoveCustomColumnMenu;

public class ReducedMenuTable extends AbstractTable {

  @Override
  protected void execAddHeaderMenus(TableEvent e) throws ProcessingException {
    if (getTableCustomizer() != null) {
      if (e.getPopupMenuCount() > 0) {
        e.addPopupMenu(new MenuSeparator());
      }
      for (IMenu m : new IMenu[]{new AddCustomColumnMenu(this), new ModifyCustomColumnMenu(this), new RemoveCustomColumnMenu(this)}) {
        m.prepareAction();
        if (m.isVisible()) {
          e.addPopupMenu(m);
        }
      }
    }
    if (e.getPopupMenuCount() > 0) {
      e.addPopupMenu(new MenuSeparator());
    }
    //for (IMenu m : new IMenu[]{new ReducedResetColumnsMenu(this), new OrganizeColumnsMenu(this)}) {
    for (IMenu m : new IMenu[]{new ReducedResetColumnsMenu(this)}) {
      m.prepareAction();
      if (m.isVisible()) {
        e.addPopupMenu(m);
      }
    }

    boolean separatorNeeded = false;
    if (e.getPopupMenuCount() > 0) {
      separatorNeeded = true;
    }
    for (IColumn c : getColumnSet().getAllColumnsInUserOrder()) {
      if (c.isDisplayable()) {
        if (separatorNeeded) {
          e.addPopupMenu(new MenuSeparator());
          separatorNeeded = false;
        }
        IMenu m = new CheckColumnMenu(this, c);
        m.prepareAction();
        m.setEnabled(true);
        e.addPopupMenu(m);
      }
    }
  }

}


org.eclipse.minicrm.client.ui.table.menus.CheckColumnMenu (a menu class that creates a toggle menu for a column with the columns name and visibility)
package org.eclipse.minicrm.client.ui.table.menus;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.minicrm.client.ui.table.IForceVisible;
import org.eclipse.minicrm.shared.Icons;
import org.eclipse.scout.commons.StringUtility;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.ClientUIPreferences;
import org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu;
import org.eclipse.scout.rt.client.ui.basic.table.IHeaderCell;
import org.eclipse.scout.rt.client.ui.basic.table.ITable;
import org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn;

public class CheckColumnMenu extends AbstractMenu {
  private final ITable m_table;
  private final IColumn m_column;
  private boolean m_forceVisible = false;

  public CheckColumnMenu(ITable table, IColumn column) {
    super();
    m_table = table;
    m_column = column;
    setText(getConfiguredText());
    setSelected(isSelected());

    if (column instanceof IForceVisible) {
      IForceVisible fv = (IForceVisible) column;
      m_forceVisible = fv.getConfiguredForceVisible();
    }
  }

  @Override
  protected String getConfiguredText() {
    String result = null;
    String tooltip = null;
    if (m_column != null) {
      IHeaderCell c = m_column.getHeaderCell();
      if (c != null) {
        result = c.getText();
        tooltip = c.getTooltipText();

        if (!StringUtility.isNullOrEmpty(tooltip)) {
          if (StringUtility.isNullOrEmpty(result)) {
            result = tooltip;
          }
          else {
            result = result + " (" + tooltip + ")";
          }
        }
      }
      if (StringUtility.isNullOrEmpty(result)) {
        result = "'" + m_column.getColumnId() + "'";
      }
    }
    return result;
  }

  @Override
  protected boolean getConfiguredToggleAction() {
    return true;
  }

  @Override
  public String getIconId() {
    return isSelected() ? Icons.Checked : Icons.Unchecked;
  }

  @Override
  public void setEnabled(boolean b) {
    if (m_forceVisible && isSelected()) {
      b = false;
    }
    super.setEnabled(b);
  }

  @Override
  public boolean isSelected() {
    return m_column.isVisible();
  }

  @Override
  protected void execAction() throws ProcessingException {
    try {
      m_table.setTableChanging(true);

      boolean visible = m_column.isVisible();
      m_column.setVisible(!visible);
      setSelected(isSelected());

      m_table.getColumnSet().setVisibleColumns(getVisibleColumns());
      ClientUIPreferences.getInstance().setAllTableColumnPreferences(m_table);
    }
    finally {
      m_table.setTableChanging(false);
    }
  }

  private IColumn[] getVisibleColumns() {
    List<IColumn> result = new ArrayList<IColumn>();
    if (m_table != null) {
      for (IColumn c : m_table.getColumnSet().getAllColumnsInUserOrder()) {
        if (c.isVisible()) {
          result.add(c);
        }
      }
    }
    return result.toArray(new IColumn[result.size()]);
  }
}


org.eclipse.minicrm.client.ui.table.menus.ReducedResetColumnsMenu (a single menu that resets all column properties)
package org.eclipse.minicrm.client.ui.table.menus;

import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu;
import org.eclipse.scout.rt.client.ui.basic.table.ITable;
import org.eclipse.scout.rt.client.ui.basic.table.columnfilter.ITableColumnFilterManager;
import org.eclipse.scout.rt.client.ui.basic.table.customizer.ITableCustomizer;
import org.eclipse.scout.rt.shared.ScoutTexts;

public class ReducedResetColumnsMenu extends AbstractMenu {
  private final ITable m_table;

  public ReducedResetColumnsMenu(ITable table) {
    m_table = table;
  }

  @Override
  protected String getConfiguredText() {
    return ScoutTexts.get("ResetTableColumns");
  }

  @Override
  protected void execAction() throws ProcessingException {
    try {
      m_table.setTableChanging(true);
      //
      m_table.resetDisplayableColumns();
      ITableColumnFilterManager m = m_table.getColumnFilterManager();
      if (m != null) {
        m.reset();
      }
      ITableCustomizer cst = m_table.getTableCustomizer();
      if (cst != null) {
        cst.removeAllColumns();
      }
    }
    finally {
      m_table.setTableChanging(false);
    }
  }
}


I can now convert any menu from the standard Scout table menus to our "simplified" menu by making the table on my page/form extend ReducedMenuTable instead of AbstractTable. Any Column that may not be hidden by the user must not only extend AbstractXxxxColumn but also implement IForceVisibile and override
      @Override
      public boolean getConfiguredForceVisible() {
        return true;
      }



And this is what 11 lines of code changes can look like using the above four classes:
index.php/fa/13921/0/
Re: Can I make table columns "un-hideable"? [message #1034773 is a reply to message #1021130] Fri, 05 April 2013 21:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi Urs
I opened a change request Bug 405052 facing your request. Thank you for this request.

/andreas
Re: Can I make table columns "un-hideable"? [message #1036285 is a reply to message #1034773] Mon, 08 April 2013 07:23 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks
Previous Topic:Datefield in RAP client
Next Topic:Showing Tables without "cellspacing" between rows
Goto Forum:
  


Current Time: Wed Apr 24 21:07:00 GMT 2024

Powered by FUDForum. Page generated in 0.03399 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top