Commit fa962695 authored by Aurelien Pupier's avatar Aurelien Pupier

Merge pull request #332 from bonitasoft/fix/BS-14360_handle_organization_switch

BS-14360 Handle active organization / repository
parents 90e1f493 e2411c8f
......@@ -12,7 +12,6 @@ Export-Package: org.bonitasoft.studio.actors,
org.bonitasoft.studio.actors.model.organization,
org.bonitasoft.studio.actors.model.organization.impl,
org.bonitasoft.studio.actors.model.organization.util,
org.bonitasoft.studio.actors.preference,
org.bonitasoft.studio.actors.repository,
org.bonitasoft.studio.actors.ui.wizard.page,
org.bonitasoft.studio.actors.validator
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -25,31 +23,35 @@ import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.extension.IEngineAction;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
/**
* @author Romain Bioteau
*
*/
public class PublishActiveOrganizationAction implements IEngineAction {
private final ActiveOrganizationProvider activeOrganizationProvider;
public PublishActiveOrganizationAction() {
activeOrganizationProvider = new ActiveOrganizationProvider();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.common.extension.IEngineAction#run(org.bonitasoft.engine.session.APISession)
*/
@Override
public void run(APISession session) throws Exception {
if(BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.LOAD_ORGANIZATION)) {
String artifactId = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(BonitaPreferenceConstants.DEFAULT_ORGANIZATION) +"."+OrganizationRepositoryStore.ORGANIZATION_EXT ;
OrganizationRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class);
OrganizationFileStore organizationFileStore = store.getChild(artifactId);
if(organizationFileStore == null){
throw new FileNotFoundException(artifactId);
public void run(final APISession session) throws Exception {
if (BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.LOAD_ORGANIZATION)) {
final String artifactId = activeOrganizationProvider.getActiveOrganization();
final OrganizationRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class);
final OrganizationFileStore organizationFileStore = store.getChild(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
if (organizationFileStore == null) {
throw new FileNotFoundException(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
}
PublishOrganizationOperation op = new PublishOrganizationOperation(organizationFileStore.getContent());
final PublishOrganizationOperation op = new PublishOrganizationOperation(organizationFileStore.getContent());
op.setSession(session);
op.run(Repository.NULL_PROGRESS_MONITOR);
}
......
......@@ -20,10 +20,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.AbstractOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.GroupsWizardPage;
......@@ -33,16 +33,18 @@ import org.bonitasoft.studio.actors.ui.wizard.page.UsersWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException;
import org.bonitasoft.studio.common.repository.preferences.OrganizationPreferenceConstants;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil;
......@@ -50,7 +52,6 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
......@@ -70,8 +71,10 @@ public class ManageOrganizationWizard extends Wizard {
private Organization activeOrganization;
private boolean activeOrganizationHasBeenModified = false;
String userName;
private final ActiveOrganizationProvider activeOrganizationProvider;
public ManageOrganizationWizard() {
activeOrganizationProvider = new ActiveOrganizationProvider();
organizations = new ArrayList<Organization>();
organizationsWorkingCopy = new ArrayList<Organization>();
setWindowTitle(Messages.manageOrganizationTitle);
......@@ -83,8 +86,10 @@ public class ManageOrganizationWizard extends Wizard {
BonitaStudioLog.error("Failed read organization content", e);
}
}
final String activeOrganizationName = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.getString(BonitaPreferenceConstants.DEFAULT_ORGANIZATION);
final IScopeContext projectScope = RepositoryManager.getInstance().getCurrentRepository().getScopeContext();
final IEclipsePreferences node = projectScope.getNode(ActorsPlugin.PLUGIN_ID);
final String activeOrganizationName = node.get(OrganizationPreferenceConstants.DEFAULT_ORGANIZATION,
OrganizationPreferenceConstants.DEFAULT_ORGANIZATION_NAME);
for (final Organization orga : organizations) {
final Organization copy = EcoreUtil.copy(orga);
if (activeOrganizationName.equals(orga.getName())) {
......@@ -190,12 +195,11 @@ public class ManageOrganizationWizard extends Wizard {
BonitaStudioLog.error(e);
return false;
}
final IPreferenceStore preferenceStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
final String pref = preferenceStore.getString(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
final boolean publishOrganization = preferenceStore.getBoolean(ActorsPreferenceConstants.PUBLISH_ORGANIZATION);
final String pref = activeOrganizationProvider.getPublishOrganizationState();
final boolean publishOrganization = activeOrganizationProvider.shouldPublishOrganization();
if (publishOrganization && MessageDialogWithToggle.ALWAYS.equals(pref)) {
try {
publishOrganization(preferenceStore);
publishOrganization();
} catch (final InvocationTargetException e) {
BonitaStudioLog.error(e);
......@@ -209,25 +213,20 @@ public class ManageOrganizationWizard extends Wizard {
Messages.organizationHasBeenModifiedTitle,
null, Messages.bind(Messages.organizationHasBeenModifiedMessage, activeOrganization.getName()), MessageDialog.WARNING, buttons, 0,
Messages.doNotDisplayAgain, false);
mdwt.setPrefStore(preferenceStore);
mdwt.setPrefKey(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
mdwt.setPrefStore(activeOrganizationProvider.getPreferenceStore());
mdwt.setPrefKey(OrganizationPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
final int index = mdwt.open();
if (index == 2) {
try {
publishOrganization(preferenceStore);
if (mdwt.getToggleState()) {
preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, true);
}
} catch (final InvocationTargetException e) {
BonitaStudioLog.error(e);
} catch (final InterruptedException e) {
publishOrganization();
activeOrganizationProvider.savePublishOrganization(mdwt.getToggleState());
} catch (final InvocationTargetException | InterruptedException e) {
BonitaStudioLog.error(e);
}
} else {
if (mdwt.getToggleState()) {
preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, false);
preferenceStore.setDefault(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION, MessageDialogWithToggle.ALWAYS);
activeOrganizationProvider.savePublishOrganization(false);
activeOrganizationProvider.savePublishOrganizationState(MessageDialogWithToggle.ALWAYS);
}
}
}
......@@ -236,13 +235,13 @@ public class ManageOrganizationWizard extends Wizard {
return true;
}
private void publishOrganization(final IPreferenceStore preferenceStore) throws InvocationTargetException, InterruptedException {
private void publishOrganization() throws InvocationTargetException, InterruptedException {
getContainer().run(true, false, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor maonitor) throws InvocationTargetException, InterruptedException {
maonitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN);
userName = preferenceStore.getString(BonitaPreferenceConstants.USER_NAME);
userName = activeOrganizationProvider.getDefaultUser();
if (isUserExist(activeOrganization.getUsers().getUser(), userName)) {
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -21,17 +19,16 @@ import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidationException;
import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.preferences.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
......@@ -39,7 +36,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
......@@ -49,7 +45,6 @@ import org.eclipse.ui.handlers.IHandlerService;
/**
* @author Romain Bioteau
*
*/
public class SynchronizeOrganizationWizard extends Wizard {
......@@ -58,43 +53,45 @@ public class SynchronizeOrganizationWizard extends Wizard {
private DefaultUserOrganizationWizardPage userPage;
private Organization activeOrganization;
private final OrganizationValidator validator;
private final ActiveOrganizationProvider activeOrganizationProvider;
public SynchronizeOrganizationWizard(){
public SynchronizeOrganizationWizard() {
setWindowTitle(Messages.synchronizeOrganizationTitle);
setDefaultPageImageDescriptor(Pics.getWizban()) ;
setForcePreviousAndNextButtons(false) ;
setNeedsProgressMonitor(true) ;
setDefaultPageImageDescriptor(Pics.getWizban());
setForcePreviousAndNextButtons(false);
setNeedsProgressMonitor(true);
validator = new OrganizationValidator();
activeOrganizationProvider = new ActiveOrganizationProvider();
}
@Override
public void addPages() {
page = new SynchronizeOrganizationWizardPage() ;
userPage = new DefaultUserOrganizationWizardPage() ;
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() ;
userPage.setUser(prefStore.getString(BonitaPreferenceConstants.USER_NAME));
// userPage.setPassword(prefStore.getString(BonitaPreferenceConstants.USER_PASSWORD));
addPage(page) ;
addPage(userPage) ;
page = new SynchronizeOrganizationWizardPage();
userPage = new DefaultUserOrganizationWizardPage();
RepositoryManager.getInstance().getCurrentRepository().getScopeContext();
userPage.setUser(activeOrganizationProvider.getDefaultUser());
addPage(page);
addPage(userPage);
}
@Override
public IWizardPage getNextPage(final IWizardPage page) {
if(page instanceof SynchronizeOrganizationWizardPage){
activeOrganization = ((SynchronizeOrganizationWizardPage)page).getFileStore().getContent();
userPage.setOrganization(activeOrganization) ;
return userPage ;
}else{
if (page instanceof SynchronizeOrganizationWizardPage) {
activeOrganization = ((SynchronizeOrganizationWizardPage) page).getFileStore().getContent();
userPage.setOrganization(activeOrganization);
return userPage;
} else {
return super.getNextPage(page);
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
final IPreferenceStore prefStore = updateDefaultUserPreference();
updateDefaultUserPreference();
final OrganizationFileStore artifact = getFileStore();
try {
getContainer().run(true, false, new IRunnableWithProgress() {
......@@ -107,23 +104,23 @@ public class SynchronizeOrganizationWizard extends Wizard {
throw new InvocationTargetException(new OrganizationValidationException(status));
}
monitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN);
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class) ;
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class) ;
final Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization") ;
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
final Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization");
try {
final Parameterization p = new Parameterization(cmd.getParameter("artifact"), artifact.getName());
handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[]{p}), null);
prefStore.setValue(ActorsPreferenceConstants.DEFAULT_ORGANIZATION, artifact.getDisplayName()) ;
handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { p }), null);
activeOrganizationProvider.saveActiveOrganization(artifact.getDisplayName());
} catch (final Exception e) {
throw new InvocationTargetException(e);
}
}
}) ;
});
} catch (final InvocationTargetException e) {
if (e.getCause() instanceof OrganizationValidationException) {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.organizationValidationFailed, e.getCause().getMessage());
}
return false ;
return false;
} catch (final InterruptedException e) {
BonitaStudioLog.error(e);
return false;
......@@ -134,8 +131,7 @@ public class SynchronizeOrganizationWizard extends Wizard {
return true;
}
protected IPreferenceStore updateDefaultUserPreference() {
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
protected void updateDefaultUserPreference() {
final String userName = userPage.getUser();
String password = null;
if (activeOrganization != null) {
......@@ -145,14 +141,12 @@ public class SynchronizeOrganizationWizard extends Wizard {
}
}
}
prefStore.setValue(BonitaPreferenceConstants.USER_NAME, userName);
prefStore.setValue(BonitaPreferenceConstants.USER_PASSWORD, password);
return prefStore;
activeOrganizationProvider.saveDefaultUser(userName);
activeOrganizationProvider.saveDefaultPassword(password);
}
public OrganizationFileStore getFileStore() {
return page.getFileStore();
}
}
......@@ -14,9 +14,9 @@
package org.bonitasoft.studio.actors.ui.wizard.connector;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.bonitasoft.studio.connector.model.definition.Checkbox;
import org.bonitasoft.studio.connector.model.definition.Page;
import org.bonitasoft.studio.connector.model.definition.Text;
......@@ -24,7 +24,6 @@ import org.bonitasoft.studio.connector.model.definition.wizard.AbstractConnector
import org.bonitasoft.studio.connector.model.definition.wizard.PageComponentSwitchBuilder;
import org.bonitasoft.studio.expression.editor.viewer.CheckBoxExpressionViewer;
import org.bonitasoft.studio.expression.editor.viewer.ExpressionViewer;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.jface.layout.GridDataFactory;
......@@ -34,17 +33,17 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
/**
* @author Elias Ricken de Medeiros
*
*/
public class CustomUserInfoConnectorConfigurationWizardPage extends AbstractConnectorConfigurationWizardPage {
private static final int LABEL_WIDTH = 250;
private final ActiveOrganizationProvider activeOrganizationProvider;
public CustomUserInfoConnectorConfigurationWizardPage() {
super(CustomUserInfoConnectorConfigurationWizardPage.class.getName());
activeOrganizationProvider = new ActiveOrganizationProvider();
}
@Override
......@@ -79,18 +78,18 @@ public class CustomUserInfoConnectorConfigurationWizardPage extends AbstractConn
final CheckBoxExpressionViewer viewer = componentSwitchBuilder.createCheckboxControl(pageComposite, automaticAssignInput);
viewer.setMessage(Messages.assignOnlyIfOneUser, IStatus.INFO);
return mainComposite ;
return mainComposite;
}
private Composite createInputsComposite(final Composite mainComposite) {
final Composite pageComposite = new Composite(mainComposite, SWT.NONE) ;
final Composite pageComposite = new Composite(mainComposite, SWT.NONE);
pageComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).spacing(3, 60).create());
pageComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
return pageComposite;
}
private Composite createMainComposite(final Composite parent) {
final Composite mainComposite = new Composite(parent, SWT.NONE) ;
final Composite mainComposite = new Composite(parent, SWT.NONE);
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 20).create());
return mainComposite;
......@@ -104,18 +103,11 @@ public class CustomUserInfoConnectorConfigurationWizardPage extends AbstractConn
private void createCustomExpressionViewerWithCustomInfo(final PageComponentSwitchBuilder componentSwitchBuilder, final Composite composite,
final Text object) {
final OrganizationRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class);
final String fileName = getCurrentOrganizationFileName();
final String fileName = activeOrganizationProvider.getActiveOrganization();
componentSwitchBuilder.createTextControl(composite, object, new CustomUserInfoNameExpressionProvider(store, fileName),
new CustomUserInfoLabelProvider());
}
private String getCurrentOrganizationFileName() {
final String activeOrganization = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore()
.getString(ActorsPreferenceConstants.DEFAULT_ORGANIZATION);
final String fileName = activeOrganization + "." + OrganizationRepositoryStore.ORGANIZATION_EXT;
return fileName;
}
private void addLabel(final Composite composite, final String label) {
final Label fieldLabel = new Label(composite, SWT.WRAP);
fieldLabel.setText(label);
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -18,10 +16,9 @@ package org.bonitasoft.studio.actors.ui.wizard.page;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.common.jface.BonitaStudioFontRegistry;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
import org.bonitasoft.studio.common.repository.core.ActiveOrganizationProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
......@@ -32,44 +29,49 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;
final class OrganizationLabelProvider extends
StyledCellLabelProvider implements ILabelProvider {
public class OrganizationLabelProvider extends StyledCellLabelProvider implements ILabelProvider {
private static Styler boldgreen = new StyledString.Styler(){
private final ActiveOrganizationProvider activeOrganizationProvider;
public OrganizationLabelProvider() {
activeOrganizationProvider = new ActiveOrganizationProvider();
}
private static Styler boldgreen = new StyledString.Styler() {
@Override
public void applyStyles(TextStyle textStyle) {
public void applyStyles(final TextStyle textStyle) {
textStyle.font = BonitaStudioFontRegistry.getActiveFont();
textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GREEN);
}
};
@Override
public String getText(Object element) {
if(element instanceof OrganizationFileStore){
return ((OrganizationFileStore)element).getDisplayName();
}else if(element instanceof Organization){
return ((Organization)element).getName();
public String getText(final Object element) {
if (element instanceof OrganizationFileStore) {
return ((OrganizationFileStore) element).getDisplayName();
} else if (element instanceof Organization) {
return ((Organization) element).getName();
}
return null;
}
@Override
public void update(ViewerCell cell) {
String orgaName = getText(cell.getElement());
String activeOrganization = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(ActorsPreferenceConstants.DEFAULT_ORGANIZATION) ;
StyledString styledString = new StyledString();
public void update(final ViewerCell cell) {
final String orgaName = getText(cell.getElement());
final String activeOrganization = activeOrganizationProvider.getActiveOrganization();
final StyledString styledString = new StyledString();
styledString.append(orgaName, null);
if(orgaName.equals(activeOrganization)){
styledString.append(" ("+Messages.active+")",boldgreen);
if (orgaName.equals(activeOrganization)) {
styledString.append(" (" + Messages.active + ")", boldgreen);
}
cell.setText(styledString.getString());
cell.setImage(null) ;
cell.setImage(null);
cell.setStyleRanges(styledString.getStyleRanges());
}
@Override
public Image getImage(Object element) {
public Image getImage(final Object element) {
return null;
}
}