Commit fa962695 authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

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, ...@@ -12,7 +12,6 @@ Export-Package: org.bonitasoft.studio.actors,
org.bonitasoft.studio.actors.model.organization, org.bonitasoft.studio.actors.model.organization,
org.bonitasoft.studio.actors.model.organization.impl, org.bonitasoft.studio.actors.model.organization.impl,
org.bonitasoft.studio.actors.model.organization.util, org.bonitasoft.studio.actors.model.organization.util,
org.bonitasoft.studio.actors.preference,
org.bonitasoft.studio.actors.repository, org.bonitasoft.studio.actors.repository,
org.bonitasoft.studio.actors.ui.wizard.page, org.bonitasoft.studio.actors.ui.wizard.page,
org.bonitasoft.studio.actors.validator org.bonitasoft.studio.actors.validator
......
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
* it under the terms of the GNU General Public License as published by * 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 * the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version. * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
...@@ -25,31 +23,35 @@ import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore; ...@@ -25,31 +23,35 @@ import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.extension.IEngineAction; import org.bonitasoft.studio.common.extension.IEngineAction;
import org.bonitasoft.studio.common.repository.Repository; import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager; 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.BonitaPreferenceConstants;
import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin; import org.bonitasoft.studio.preferences.BonitaStudioPreferencesPlugin;
/** /**
* @author Romain Bioteau * @author Romain Bioteau
*
*/ */
public class PublishActiveOrganizationAction implements IEngineAction { 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) * @see org.bonitasoft.studio.common.extension.IEngineAction#run(org.bonitasoft.engine.session.APISession)
*/ */
@Override @Override
public void run(APISession session) throws Exception { public void run(final APISession session) throws Exception {
if(BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.LOAD_ORGANIZATION)) { if (BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.LOAD_ORGANIZATION)) {
String artifactId = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getString(BonitaPreferenceConstants.DEFAULT_ORGANIZATION) +"."+OrganizationRepositoryStore.ORGANIZATION_EXT ; final String artifactId = activeOrganizationProvider.getActiveOrganization();
OrganizationRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class); final OrganizationRepositoryStore store = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class);
OrganizationFileStore organizationFileStore = store.getChild(artifactId); final OrganizationFileStore organizationFileStore = store.getChild(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
if(organizationFileStore == null){ if (organizationFileStore == null) {
throw new FileNotFoundException(artifactId); throw new FileNotFoundException(artifactId + "." + OrganizationRepositoryStore.ORGANIZATION_EXT);
} }
PublishOrganizationOperation op = new PublishOrganizationOperation(organizationFileStore.getContent()); final PublishOrganizationOperation op = new PublishOrganizationOperation(organizationFileStore.getContent());
op.setSession(session); op.setSession(session);
op.run(Repository.NULL_PROGRESS_MONITOR); op.run(Repository.NULL_PROGRESS_MONITOR);
} }
......
...@@ -20,10 +20,10 @@ import java.util.HashMap; ...@@ -20,10 +20,10 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.i18n.Messages; import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization; import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.User; 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.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.AbstractOrganizationWizardPage; import org.bonitasoft.studio.actors.ui.wizard.page.AbstractOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.GroupsWizardPage; import org.bonitasoft.studio.actors.ui.wizard.page.GroupsWizardPage;
...@@ -33,16 +33,18 @@ import org.bonitasoft.studio.actors.ui.wizard.page.UsersWizardPage; ...@@ -33,16 +33,18 @@ import org.bonitasoft.studio.actors.ui.wizard.page.UsersWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidator; import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog; import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager; 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.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.ReadFileStoreException; 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.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.Command;
import org.eclipse.core.commands.Parameterization; import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; 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.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter; import org.eclipse.emf.ecore.util.EContentAdapter;
import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.EcoreUtil;
...@@ -50,7 +52,6 @@ import org.eclipse.jface.dialogs.IDialogConstants; ...@@ -50,7 +52,6 @@ import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
...@@ -70,8 +71,10 @@ public class ManageOrganizationWizard extends Wizard { ...@@ -70,8 +71,10 @@ public class ManageOrganizationWizard extends Wizard {
private Organization activeOrganization; private Organization activeOrganization;
private boolean activeOrganizationHasBeenModified = false; private boolean activeOrganizationHasBeenModified = false;
String userName; String userName;
private final ActiveOrganizationProvider activeOrganizationProvider;
public ManageOrganizationWizard() { public ManageOrganizationWizard() {
activeOrganizationProvider = new ActiveOrganizationProvider();
organizations = new ArrayList<Organization>(); organizations = new ArrayList<Organization>();
organizationsWorkingCopy = new ArrayList<Organization>(); organizationsWorkingCopy = new ArrayList<Organization>();
setWindowTitle(Messages.manageOrganizationTitle); setWindowTitle(Messages.manageOrganizationTitle);
...@@ -83,8 +86,10 @@ public class ManageOrganizationWizard extends Wizard { ...@@ -83,8 +86,10 @@ public class ManageOrganizationWizard extends Wizard {
BonitaStudioLog.error("Failed read organization content", e); BonitaStudioLog.error("Failed read organization content", e);
} }
} }
final String activeOrganizationName = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() final IScopeContext projectScope = RepositoryManager.getInstance().getCurrentRepository().getScopeContext();
.getString(BonitaPreferenceConstants.DEFAULT_ORGANIZATION); 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) { for (final Organization orga : organizations) {
final Organization copy = EcoreUtil.copy(orga); final Organization copy = EcoreUtil.copy(orga);
if (activeOrganizationName.equals(orga.getName())) { if (activeOrganizationName.equals(orga.getName())) {
...@@ -190,12 +195,11 @@ public class ManageOrganizationWizard extends Wizard { ...@@ -190,12 +195,11 @@ public class ManageOrganizationWizard extends Wizard {
BonitaStudioLog.error(e); BonitaStudioLog.error(e);
return false; return false;
} }
final IPreferenceStore preferenceStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore(); final String pref = activeOrganizationProvider.getPublishOrganizationState();
final String pref = preferenceStore.getString(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION); final boolean publishOrganization = activeOrganizationProvider.shouldPublishOrganization();
final boolean publishOrganization = preferenceStore.getBoolean(ActorsPreferenceConstants.PUBLISH_ORGANIZATION);
if (publishOrganization && MessageDialogWithToggle.ALWAYS.equals(pref)) { if (publishOrganization && MessageDialogWithToggle.ALWAYS.equals(pref)) {
try { try {
publishOrganization(preferenceStore); publishOrganization();
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
BonitaStudioLog.error(e); BonitaStudioLog.error(e);
...@@ -209,25 +213,20 @@ public class ManageOrganizationWizard extends Wizard { ...@@ -209,25 +213,20 @@ public class ManageOrganizationWizard extends Wizard {
Messages.organizationHasBeenModifiedTitle, Messages.organizationHasBeenModifiedTitle,
null, Messages.bind(Messages.organizationHasBeenModifiedMessage, activeOrganization.getName()), MessageDialog.WARNING, buttons, 0, null, Messages.bind(Messages.organizationHasBeenModifiedMessage, activeOrganization.getName()), MessageDialog.WARNING, buttons, 0,
Messages.doNotDisplayAgain, false); Messages.doNotDisplayAgain, false);
mdwt.setPrefStore(preferenceStore); mdwt.setPrefStore(activeOrganizationProvider.getPreferenceStore());
mdwt.setPrefKey(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION); mdwt.setPrefKey(OrganizationPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION);
final int index = mdwt.open(); final int index = mdwt.open();
if (index == 2) { if (index == 2) {
try { try {
publishOrganization(preferenceStore); publishOrganization();
if (mdwt.getToggleState()) { activeOrganizationProvider.savePublishOrganization(mdwt.getToggleState());
preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, true); } catch (final InvocationTargetException | InterruptedException e) {
}
} catch (final InvocationTargetException e) {
BonitaStudioLog.error(e);
} catch (final InterruptedException e) {
BonitaStudioLog.error(e); BonitaStudioLog.error(e);
} }
} else { } else {
if (mdwt.getToggleState()) { if (mdwt.getToggleState()) {
preferenceStore.setDefault(ActorsPreferenceConstants.PUBLISH_ORGANIZATION, false); activeOrganizationProvider.savePublishOrganization(false);
preferenceStore.setDefault(ActorsPreferenceConstants.TOGGLE_STATE_FOR_PUBLISH_ORGANIZATION, MessageDialogWithToggle.ALWAYS); activeOrganizationProvider.savePublishOrganizationState(MessageDialogWithToggle.ALWAYS);
} }
} }
} }
...@@ -236,13 +235,13 @@ public class ManageOrganizationWizard extends Wizard { ...@@ -236,13 +235,13 @@ public class ManageOrganizationWizard extends Wizard {
return true; return true;
} }
private void publishOrganization(final IPreferenceStore preferenceStore) throws InvocationTargetException, InterruptedException { private void publishOrganization() throws InvocationTargetException, InterruptedException {
getContainer().run(true, false, new IRunnableWithProgress() { getContainer().run(true, false, new IRunnableWithProgress() {
@Override @Override
public void run(final IProgressMonitor maonitor) throws InvocationTargetException, InterruptedException { public void run(final IProgressMonitor maonitor) throws InvocationTargetException, InterruptedException {
maonitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN); maonitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN);
userName = preferenceStore.getString(BonitaPreferenceConstants.USER_NAME); userName = activeOrganizationProvider.getDefaultUser();
if (isUserExist(activeOrganization.getUsers().getUser(), userName)) { if (isUserExist(activeOrganization.getUsers().getUser(), userName)) {
......
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
* it under the terms of the GNU General Public License as published by * 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 * the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version. * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
...@@ -21,17 +19,16 @@ import java.lang.reflect.InvocationTargetException; ...@@ -21,17 +19,16 @@ import java.lang.reflect.InvocationTargetException;
import org.bonitasoft.studio.actors.i18n.Messages; import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.model.organization.Organization; import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.User; 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.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage; import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage; import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidationException; import org.bonitasoft.studio.actors.validator.OrganizationValidationException;
import org.bonitasoft.studio.actors.validator.OrganizationValidator; import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog; 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.IRepositoryFileStore;
import org.bonitasoft.studio.pics.Pics; 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.Command;
import org.eclipse.core.commands.Parameterization; import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand; import org.eclipse.core.commands.ParameterizedCommand;
...@@ -39,7 +36,6 @@ import org.eclipse.core.runtime.IProgressMonitor; ...@@ -39,7 +36,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
...@@ -49,7 +45,6 @@ import org.eclipse.ui.handlers.IHandlerService; ...@@ -49,7 +45,6 @@ import org.eclipse.ui.handlers.IHandlerService;
/** /**
* @author Romain Bioteau * @author Romain Bioteau
*
*/ */
public class SynchronizeOrganizationWizard extends Wizard { public class SynchronizeOrganizationWizard extends Wizard {
...@@ -58,43 +53,45 @@ public class SynchronizeOrganizationWizard extends Wizard { ...@@ -58,43 +53,45 @@ public class SynchronizeOrganizationWizard extends Wizard {
private DefaultUserOrganizationWizardPage userPage; private DefaultUserOrganizationWizardPage userPage;
private Organization activeOrganization; private Organization activeOrganization;
private final OrganizationValidator validator; private final OrganizationValidator validator;
private final ActiveOrganizationProvider activeOrganizationProvider;
public SynchronizeOrganizationWizard(){ public SynchronizeOrganizationWizard() {
setWindowTitle(Messages.synchronizeOrganizationTitle); setWindowTitle(Messages.synchronizeOrganizationTitle);
setDefaultPageImageDescriptor(Pics.getWizban()) ; setDefaultPageImageDescriptor(Pics.getWizban());
setForcePreviousAndNextButtons(false) ; setForcePreviousAndNextButtons(false);
setNeedsProgressMonitor(true) ; setNeedsProgressMonitor(true);
validator = new OrganizationValidator(); validator = new OrganizationValidator();
activeOrganizationProvider = new ActiveOrganizationProvider();
} }
@Override @Override
public void addPages() { public void addPages() {
page = new SynchronizeOrganizationWizardPage() ; page = new SynchronizeOrganizationWizardPage();
userPage = new DefaultUserOrganizationWizardPage() ; userPage = new DefaultUserOrganizationWizardPage();
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore() ; RepositoryManager.getInstance().getCurrentRepository().getScopeContext();
userPage.setUser(prefStore.getString(BonitaPreferenceConstants.USER_NAME)); userPage.setUser(activeOrganizationProvider.getDefaultUser());
// userPage.setPassword(prefStore.getString(BonitaPreferenceConstants.USER_PASSWORD)); addPage(page);
addPage(page) ; addPage(userPage);
addPage(userPage) ;
} }
@Override @Override
public IWizardPage getNextPage(final IWizardPage page) { public IWizardPage getNextPage(final IWizardPage page) {
if(page instanceof SynchronizeOrganizationWizardPage){ if (page instanceof SynchronizeOrganizationWizardPage) {
activeOrganization = ((SynchronizeOrganizationWizardPage)page).getFileStore().getContent(); activeOrganization = ((SynchronizeOrganizationWizardPage) page).getFileStore().getContent();
userPage.setOrganization(activeOrganization) ; userPage.setOrganization(activeOrganization);
return userPage ; return userPage;
}else{ } else {
return super.getNextPage(page); return super.getNextPage(page);
} }
} }
/* (non-Javadoc) /*
* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish() * @see org.eclipse.jface.wizard.Wizard#performFinish()
*/ */
@Override @Override
public boolean performFinish() { public boolean performFinish() {
final IPreferenceStore prefStore = updateDefaultUserPreference(); updateDefaultUserPreference();
final OrganizationFileStore artifact = getFileStore(); final OrganizationFileStore artifact = getFileStore();
try { try {
getContainer().run(true, false, new IRunnableWithProgress() { getContainer().run(true, false, new IRunnableWithProgress() {
...@@ -107,23 +104,23 @@ public class SynchronizeOrganizationWizard extends Wizard { ...@@ -107,23 +104,23 @@ public class SynchronizeOrganizationWizard extends Wizard {
throw new InvocationTargetException(new OrganizationValidationException(status)); throw new InvocationTargetException(new OrganizationValidationException(status));
} }
monitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN); monitor.beginTask(Messages.synchronizingOrganization, IProgressMonitor.UNKNOWN);
final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class) ; final ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class) ; final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
final Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization") ; final Command cmd = service.getCommand("org.bonitasoft.studio.engine.installOrganization");
try { try {
final Parameterization p = new Parameterization(cmd.getParameter("artifact"), artifact.getName()); final Parameterization p = new Parameterization(cmd.getParameter("artifact"), artifact.getName());
handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[]{p}), null); handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { p }), null);
prefStore.setValue(ActorsPreferenceConstants.DEFAULT_ORGANIZATION, artifact.getDisplayName()) ; activeOrganizationProvider.saveActiveOrganization(artifact.getDisplayName());
} catch (final Exception e) { } catch (final Exception e) {
throw new InvocationTargetException(e); throw new InvocationTargetException(e);
} }
} }
}) ; });
} catch (final InvocationTargetException e) { } catch (final InvocationTargetException e) {
if (e.getCause() instanceof OrganizationValidationException) { if (e.getCause() instanceof OrganizationValidationException) {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.organizationValidationFailed, e.getCause().getMessage()); MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.organizationValidationFailed, e.getCause().getMessage());
} }
return false ; return false;
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
BonitaStudioLog.error(e); BonitaStudioLog.error(e);
return false; return false;
...@@ -134,8 +131,7 @@ public class SynchronizeOrganizationWizard extends Wizard { ...@@ -134,8 +131,7 @@ public class SynchronizeOrganizationWizard extends Wizard {
return true; return true;
} }
protected IPreferenceStore updateDefaultUserPreference() { protected void updateDefaultUserPreference() {
final IPreferenceStore prefStore = BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore();
final String userName = userPage.getUser(); final String userName = userPage.getUser();
String password = null; String password = null;
if (activeOrganization != null) { if (activeOrganization != null) {
...@@ -145,14 +141,12 @@ public class SynchronizeOrganizationWizard extends Wizard { ...@@ -145,14 +141,12 @@ public class SynchronizeOrganizationWizard extends Wizard {
} }
} }
} }
prefStore.setValue(BonitaPreferenceConstants.USER_NAME, userName); activeOrganizationProvider.saveDefaultUser(userName);
prefStore.setValue(BonitaPreferenceConstants.USER_PASSWORD, password); activeOrganizationProvider.saveDefaultPassword(password);
return prefStore;
} }
public OrganizationFileStore getFileStore() { public OrganizationFileStore getFileStore() {
return page.getFileStore(); return page.getFileStore();
} }
} }
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
package org.bonitasoft.studio.actors.ui.wizard.connector; package org.bonitasoft.studio.actors.ui.wizard.connector;
import org.bonitasoft.studio.actors.i18n.Messages; 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.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.common.repository.RepositoryManager; 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.Checkbox;