Commit 7b18d199 authored by Romain Bioteau's avatar Romain Bioteau

BS-9777

Improve group path combo.
parent 6189b764
......@@ -53,7 +53,8 @@ Require-Bundle: org.eclipse.core.runtime,
assertj-core;bundle-version="1.5.0";resolution:=optional,
org.junit;bundle-version="4.11.0";resolution:=optional,
org.mockito;bundle-version="1.9.5";resolution:=optional,
org.bonitasoft.studio.expression.editor
org.bonitasoft.studio.expression.editor,
org.apache.commons.lang;bundle-version="2.6.0"
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.api,
org.bonitasoft.engine.bpm,
......
......@@ -255,6 +255,4 @@ defaultCustomUserInformationName=Information
nameLimitSize=the name is limited to 50 char
displayNameLimitSize=the display name is limited to 75 char
labelExplicationCustomUserInformation=The information below (default and custom) applies to all users. Custom information can be used in the processes (e.g. by implementing actor filters on tasks).
ayNameLimitSize=the display name is limited to 75 char
labelExplicationCustomUserInformation=The information below (default and custom) applies to all users. Custom information can be used in the processes (e.g. by implementing actor filters on tasks).
details=Details
\ No newline at end of file
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
import static org.assertj.core.api.Assertions.assertThat;
import org.bonitasoft.studio.actors.model.organization.Group;
import org.bonitasoft.studio.actors.model.organization.OrganizationFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Romain Bioteau
*
*/
public class OrganizationGroupLabelProviderTest {
private OrganizationGroupLabelProvider organizationGroupLabelProvider;
private Group shortGroup;
private Group longGroup;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
organizationGroupLabelProvider = new OrganizationGroupLabelProvider();
longGroup = OrganizationFactory.eINSTANCE.createGroup();
longGroup.setName("longGroup");
longGroup.setParentPath("/acme/group1/group2/group3/group4/group5/group6");
shortGroup = OrganizationFactory.eINSTANCE.createGroup();
shortGroup.setName("shortGroup");
shortGroup.setParentPath("/acme/");
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void should_getText_returns_group_path() throws Exception {
assertThat(organizationGroupLabelProvider.getText(shortGroup)).isEqualTo(GroupContentProvider.getGroupPath(shortGroup));
}
@Test
public void should_getText_returns_group_path_with_ellipsis() throws Exception {
assertThat(organizationGroupLabelProvider.getText(longGroup)).hasSize(OrganizationGroupLabelProvider.MAX_GROUP_PATH_LENGTH).endsWith("longGroup")
.contains("...");
}
@Test
public void should_getText_returns_empty_string() throws Exception {
assertThat(organizationGroupLabelProvider.getText(null)).isEmpty();
}
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
import org.bonitasoft.studio.actors.model.organization.Group;
import org.eclipse.jface.viewers.LabelProvider;
/**
* @author Romain Bioteau
*
*/
public class OrganizationGroupLabelProvider extends LabelProvider {
protected static final int MAX_GROUP_PATH_LENGTH = 30;
@Override
public String getText(final Object element) {
if (element instanceof Group) {
final String groupPath = GroupContentProvider.getGroupPath((Group) element);
if (groupPath.length() > MAX_GROUP_PATH_LENGTH) {
return org.apache.commons.lang.StringUtils.abbreviateMiddle(groupPath, "...", 30);
}
return groupPath;
}
return super.getText(element);
}
}
......@@ -19,6 +19,7 @@ package org.bonitasoft.studio.actors.ui.wizard.page;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
......@@ -551,47 +552,47 @@ public class UsersWizardPage extends AbstractOrganizationWizardPage {
private void handleFirstNameChange(final ValueChangeEvent event) {
final User user = (User) userSingleSelectionObservable.getValue();
if (user != null) {
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if (oldValue != null && oldUser != null) {
oldUser.setFirstName(oldValue.toString());
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if (oldValue != null && oldUser != null) {
oldUser.setFirstName(oldValue.toString());
if(getViewer() != null && !getViewer().getControl().isDisposed()){
getViewer().refresh(user) ;
if(getViewer() != null && !getViewer().getControl().isDisposed()){
getViewer().refresh(user) ;
}
}
}
}
}
private void handleLastNameChange(final ValueChangeEvent event) {
final User user = (User) userSingleSelectionObservable.getValue();
if (user != null) {
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if(oldValue!=null){
oldUser.setLastName(oldValue.toString());
if(getViewer() != null && !getViewer().getControl().isDisposed()){
getViewer().refresh(user) ;
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if(oldValue!=null){
oldUser.setLastName(oldValue.toString());
if(getViewer() != null && !getViewer().getControl().isDisposed()){
getViewer().refresh(user) ;
}
}
}
}
}
private void handleUserNameChange(final ValueChangeEvent event) {
final User user = (User) userSingleSelectionObservable.getValue();
if (user != null) {
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if (oldValue != null) {
if (oldUser != null) {
oldUser.setUserName(oldValue.toString());
}
if (getViewer() != null && !getViewer().getControl().isDisposed()) {
getViewer().refresh(user);
final User oldUser = EcoreUtil.copy(user);
final Object oldValue = event.diff.getOldValue();
if (oldValue != null) {
if (oldUser != null) {
oldUser.setUserName(oldValue.toString());
}
if (getViewer() != null && !getViewer().getControl().isDisposed()) {
getViewer().refresh(user);
}
}
}
}
}
/**
* @return
......@@ -779,29 +780,30 @@ public class UsersWizardPage extends AbstractOrganizationWizardPage {
groupName.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
groupName.setText(Messages.groupName);
final Combo groupNameCombo = new Combo(detailsInfoComposite, SWT.BORDER | SWT.READ_ONLY) ;
groupNameCombo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(100, SWT.DEFAULT).create()) ;
final ComboViewer groupNameCombo = new ComboViewer(detailsInfoComposite, SWT.BORDER | SWT.READ_ONLY);
groupNameCombo.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(100, SWT.DEFAULT).create());
groupNameCombo.setContentProvider(new ObservableListContentProvider());
groupNameCombo.setLabelProvider(new OrganizationGroupLabelProvider());
// for(final org.bonitasoft.studio.actors.model.organization.Group g : groupList){
// groupNameCombo.add(GroupContentProvider.getGroupPath(g)) ;
// }
for(final org.bonitasoft.studio.actors.model.organization.Group g : groupList){
groupNameCombo.add(GroupContentProvider.getGroupPath(g)) ;
}
final IObservableList observeGroupList = EMFObservables.observeList(organization.getGroups(), OrganizationPackage.Literals.GROUPS__GROUP);
final UpdateValueStrategy targetStrategy = new UpdateValueStrategy();
targetStrategy.setAfterGetValidator(new EmptyInputValidator(Messages.emtpyMembershipValue));
targetStrategy.setConverter(new Converter(String.class,String.class) {
targetStrategy.setConverter(new Converter(org.bonitasoft.studio.actors.model.organization.Group.class, String.class) {
@Override
public Object convert(final Object from) {
final String path = (String) from ;
if(!path.isEmpty()){
final String parentPath = path.substring(0, path.lastIndexOf(GroupContentProvider.GROUP_SEPARATOR)) ;
final String groupName = path.substring(path.lastIndexOf(GroupContentProvider.GROUP_SEPARATOR)+1,path.length()) ;
if(parentPath.isEmpty()){
final org.bonitasoft.studio.actors.model.organization.Group group = (org.bonitasoft.studio.actors.model.organization.Group) from;
if (group != null) {
if (group.getParentPath() == null || group.getParentPath().isEmpty()) {
membership.setGroupParentPath(null) ;
}else{
membership.setGroupParentPath(parentPath) ;
membership.setGroupParentPath(group.getParentPath());
}
return groupName;
return group.getName();
}else{
return "";
}
......@@ -809,26 +811,32 @@ public class UsersWizardPage extends AbstractOrganizationWizardPage {
});
final UpdateValueStrategy modelStrategy = new UpdateValueStrategy();
modelStrategy.setConverter(new Converter(String.class,String.class) {
modelStrategy.setConverter(new Converter(String.class, org.bonitasoft.studio.actors.model.organization.Group.class) {
@Override
public Object convert(final Object from) {
if(membership.getGroupParentPath() != null && !membership.getGroupParentPath().isEmpty()){
String parentPath = membership.getGroupParentPath() ;
if(!membership.getGroupParentPath().endsWith(GroupContentProvider.GROUP_SEPARATOR)){
parentPath = parentPath + GroupContentProvider.GROUP_SEPARATOR ;
final String groupName = (String) from;
final Iterator<org.bonitasoft.studio.actors.model.organization.Group> iterator = observeGroupList.iterator();
while (iterator.hasNext()) {
final org.bonitasoft.studio.actors.model.organization.Group group = iterator.next();
if (group.getName().equals(groupName)) {
final String gParentPath = group.getParentPath();
final String mGroupParentPath = membership.getGroupParentPath();
if (gParentPath == null && mGroupParentPath == null || gParentPath.equals(mGroupParentPath)) {
return group;
}
}
final String path = parentPath + from ;
return path ;
}else if(from!= null && !from.toString().isEmpty()){
return GroupContentProvider.GROUP_SEPARATOR + membership.getGroupName() ;
}else{
return "";
}
return null;
}
});
groupNameCombo.setInput(observeGroupList);
final IObservableValue membershipValue = EMFObservables.observeValue(membership, OrganizationPackage.Literals.MEMBERSHIP__GROUP_NAME);
final Binding binding = context.bindValue(SWTObservables.observeText(groupNameCombo), membershipValue, targetStrategy, modelStrategy);
final Binding binding = context.bindValue(ViewersObservables.observeSingleSelection(groupNameCombo), membershipValue, targetStrategy, modelStrategy);
ControlDecorationSupport.create(binding, SWT.LEFT,detailsInfoComposite);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment