use of com.vaadin.v7.ui.Select in project opencms-core by alkacon.
the class CmsEditSiteForm method setUpComboBoxPosition.
/**
* Set the combo box for the position.<p>
* Copied from workplace tool.<p>
*/
private void setUpComboBoxPosition() {
m_fieldPosition.removeAllItems();
List<CmsSite> sites = new ArrayList<CmsSite>();
List<PositionComboBoxElementBean> beanList = new ArrayList<PositionComboBoxElementBean>();
for (CmsSite site : OpenCms.getSiteManager().getAvailableSites(m_clonedCms, true)) {
if (site.getSiteMatcher() != null) {
sites.add(site);
}
}
float maxValue = 0;
float nextPos = 0;
// calculate value for the first navigation position
float firstValue = 1;
if (sites.size() > 0) {
try {
maxValue = sites.get(0).getPosition();
} catch (Exception e) {
// should usually never happen
}
}
if (maxValue != 0) {
firstValue = maxValue / 2;
}
// add the first entry: before first element
beanList.add(new PositionComboBoxElementBean(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_FIRST_0), firstValue));
// show all present navigation elements in box
for (int i = 0; i < sites.size(); i++) {
float navPos = sites.get(i).getPosition();
String siteRoot = sites.get(i).getSiteRoot();
// get position of next nav element
nextPos = navPos + 2;
if ((i + 1) < sites.size()) {
nextPos = sites.get(i + 1).getPosition();
}
// calculate new position of current nav element
float newPos;
if ((nextPos - navPos) > 1) {
newPos = navPos + 1;
} else {
newPos = (navPos + nextPos) / 2;
}
// check new maxValue of positions and increase it
if (navPos > maxValue) {
maxValue = navPos;
}
// if the element is the current file, mark it in select box
if ((m_site != null) && (m_site.getSiteRoot() != null) && m_site.getSiteRoot().equals(siteRoot)) {
beanList.add(new PositionComboBoxElementBean(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_CURRENT_1, m_site.getTitle()), -1));
} else {
beanList.add(new PositionComboBoxElementBean(sites.get(i).getTitle(), newPos));
}
}
// add the entry: at the last position
PositionComboBoxElementBean lastEntry = new PositionComboBoxElementBean(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_LAST_0), maxValue + 1);
beanList.add(lastEntry);
// add the entry: no change
beanList.add(new PositionComboBoxElementBean(CmsVaadinUtils.getMessageText(Messages.GUI_SITE_CHNAV_POS_NOCHANGE_0), -1));
BeanItemContainer<PositionComboBoxElementBean> objects = new BeanItemContainer<PositionComboBoxElementBean>(PositionComboBoxElementBean.class, beanList);
m_fieldPosition.setContainerDataSource(objects);
m_fieldPosition.setItemCaptionPropertyId("title");
m_fieldPosition.setValue(beanList.get(beanList.size() - 1));
if (m_site == null) {
m_fieldPosition.setValue(lastEntry);
}
}
use of com.vaadin.v7.ui.Select in project opencms-core by alkacon.
the class CmsOUTable method init.
/**
* initializes table.<p>
*
* @param parentOu ou name
*/
private void init(String parentOu) {
m_parentOu = parentOu;
m_menu = new CmsContextMenu();
m_menu.setAsTableContextMenu(this);
m_container = new IndexedContainer();
setContainerDataSource(m_container);
for (TableProperty prop : TableProperty.values()) {
m_container.addContainerProperty(prop, prop.getType(), prop.getDefault());
setColumnHeader(prop, prop.getName());
}
setContainerDataSource(m_container);
setItemIconPropertyId(TableProperty.Icon);
setRowHeaderMode(RowHeaderMode.ICON_ONLY);
setColumnWidth(null, 40);
setSelectable(true);
addGeneratedColumn(TableProperty.Ressources, new ColumnGenerator() {
private static final long serialVersionUID = 4624734503799549261L;
public Object generateCell(Table source, Object itemId, Object columnId) {
String out = "";
try {
boolean isOu = true;
for (I_CmsOuTreeType type : m_app.getTreeTypeProvider().getTreeTypes()) {
if (type.getId().equals(itemId)) {
isOu = false;
}
}
if (isOu) {
List<CmsResource> resources = OpenCms.getOrgUnitManager().getResourcesForOrganizationalUnit(m_cms, (String) itemId);
if (!resources.isEmpty()) {
out = resources.get(0).getRootPath();
int i = 1;
while ((resources.size() > i) & (out.length() < 50)) {
out += ", " + resources.get(i).getRootPath();
}
if (resources.size() > i) {
out += " ...";
}
}
}
} catch (CmsException e) {
LOG.error("unable to read resources.", e);
}
return out;
}
});
setVisibleColumns(TableProperty.Name, TableProperty.Description, TableProperty.Ressources);
try {
m_cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
m_cms.getRequestContext().setSiteRoot("");
} catch (CmsException e) {
m_cms = A_CmsUI.getCmsObject();
}
try {
if (m_app.isOUManagable(m_parentOu)) {
for (I_CmsOuTreeType treeType : m_app.getTreeTypeProvider().getTreeTypes()) {
if (treeType.showInOuTable() && treeType.isValidForOu(m_cms, m_parentOu)) {
Item item = m_container.addItem(treeType.getId());
item.getItemProperty(TableProperty.Name).setValue(treeType.getName());
item.getItemProperty(TableProperty.Icon).setValue(treeType.getIcon());
item.getItemProperty(TableProperty.Type).setValue(treeType);
}
}
}
List<CmsOrganizationalUnit> webOus = new ArrayList<CmsOrganizationalUnit>();
for (CmsOrganizationalUnit ou : OpenCms.getOrgUnitManager().getOrganizationalUnits(m_cms, parentOu, false)) {
if (ou.hasFlagWebuser()) {
webOus.add(ou);
} else {
addOuToTable(ou);
}
}
for (CmsOrganizationalUnit ou : webOus) {
addOuToTable(ou);
}
} catch (CmsException e) {
LOG.error("Unable to read ous", e);
}
addItemClickListener(new ItemClickListener() {
private static final long serialVersionUID = 4807195510202231174L;
public void itemClick(ItemClickEvent event) {
setValue(null);
select(event.getItemId());
if (event.getButton().equals(MouseButton.RIGHT) || (event.getPropertyId() == null)) {
m_menu.setEntries(getMenuEntries(), Collections.singleton((String) getValue()));
m_menu.openForTable(event, event.getItemId(), event.getPropertyId(), CmsOUTable.this);
return;
}
if (event.getButton().equals(MouseButton.LEFT) && event.getPropertyId().equals(TableProperty.Name)) {
updateApp((String) getValue());
}
}
});
setCellStyleGenerator(new CellStyleGenerator() {
private static final long serialVersionUID = 1L;
public String getStyle(Table source, Object itemId, Object propertyId) {
if (TableProperty.Name.equals(propertyId)) {
return " " + OpenCmsTheme.HOVER_COLUMN;
}
return "";
}
});
}
Aggregations