Commit 592e416e authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-10855

parent e45d8112
......@@ -256,4 +256,6 @@ 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).
details=Details
groupDisplayLengthTooLong=Group display name \"{0}\" exceed max length of 75 characters.
\ No newline at end of file
groupDisplayLengthTooLong=Group display name \"{0}\" exceed max length of 75 characters.
importOrganizationWithWarningTitle=Import completed with errors
importOrganizationWithWarningMessage=The import of organization completed but some errors has been found.\n{0}
\ No newline at end of file
......@@ -280,6 +280,8 @@ public class Messages extends NLS {
public static String customUserInfoValueLimitSize;
public static String userNameIsEmpty;
public static String groupDisplayLengthTooLong;
public static String importOrganizationWithWarningTitle;
public static String importOrganizationWithWarningMessage;
}
......@@ -25,7 +25,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CancellationException;
import org.bonitasoft.studio.actors.ActorsPlugin;
import org.bonitasoft.studio.actors.i18n.Messages;
......@@ -131,20 +130,10 @@ public class OrganizationRepositoryStore extends AbstractEMFRepositoryStore<Orga
final Organization orga = fileStore.getContent() ;
if(orga != null && (orga.getName() == null || orga.getName().isEmpty())){
orga.setName(newFileName.substring(0,newFileName.length()-ORGANIZATION_EXT.length() - 1)) ;
// final IStatus status = new OrganizationValidator().validate(orga);
//if(status.isOK()){
fileStore.save(orga) ;
//}else{
// fileStore.delete();
// throw new CancellationException(status.getMessage());
// }
fileStore.save(orga);
}
}
}catch(final Exception e){
if(e instanceof CancellationException){
throw (CancellationException)e;
}
BonitaStudioLog.error(e) ;
return null;
}
......
......@@ -25,6 +25,7 @@ import java.util.concurrent.CancellationException;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
......@@ -33,6 +34,7 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
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.swt.SWT;
......@@ -51,28 +53,37 @@ public class ImportOrganizationHandler extends AbstractHandler {
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final OrganizationRepositoryStore organizationStore = (OrganizationRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class) ;
FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(),SWT.OPEN) ;
public Object execute(final ExecutionEvent event) throws ExecutionException {
final OrganizationRepositoryStore organizationStore = RepositoryManager.getInstance().getRepositoryStore(OrganizationRepositoryStore.class) ;
final FileDialog fd = new FileDialog(Display.getDefault().getActiveShell(),SWT.OPEN) ;
fd.setFilterExtensions(new String[]{"*.xml;*.zip"}) ;
final String filePath = fd.open() ;
if(filePath != null){
IProgressService service = PlatformUI.getWorkbench().getProgressService() ;
final IProgressService service = PlatformUI.getWorkbench().getProgressService() ;
try {
service.run(false, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException,
public void run(final IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
monitor.beginTask(Messages.importingOrganization, IProgressMonitor.UNKNOWN) ;
FileInputStream fis = null ;
try {
fis = new FileInputStream(filePath);
String id = new File(filePath).getName() ;
final String id = new File(filePath).getName() ;
FileActionDialog.setThrowExceptionOnCancel(true);
OrganizationFileStore file = organizationStore.importInputStream(id, fis) ;
final OrganizationFileStore file = organizationStore.importInputStream(id, fis) ;
if(file != null && file.isCorrectlySyntaxed()){
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.importOrganizationSuccessfullTitle, Messages.importOrganizationSuccessfullMessage);
final IStatus status = new OrganizationValidator().validate(file.getContent());
if (!status.isOK()) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.importOrganizationWithWarningTitle,
Messages.bind(Messages.importOrganizationWithWarningMessage,status.getMessage()));
} else {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.importOrganizationSuccessfullTitle,
Messages.importOrganizationSuccessfullMessage);
}
} else {
fis.close();
if( file != null){
......@@ -80,15 +91,15 @@ public class ImportOrganizationHandler extends AbstractHandler {
}
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.importOrganizationFailedTitle, Messages.importOrganizationFailedMessage);
}
} catch(CancellationException ce) {
} catch(final CancellationException ce) {
String message = Messages.importOrganizationCancelledMessage;
if(ce.getMessage() != null){
message = Messages.importOrganizationCancelledMessage + ":\n"+ce.getMessage();
}
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.importOrganizationCancelledTitle, message);
} catch (Exception e) {
BonitaStudioLog.error(e) ;
OrganizationFileStore file = organizationStore.getChild(new File(filePath).getName().replace(".xml", "."+OrganizationRepositoryStore.ORGANIZATION_EXT));
} catch (final Exception e) {
BonitaStudioLog.error(e) ;
final OrganizationFileStore file = organizationStore.getChild(new File(filePath).getName().replace(".xml", "."+OrganizationRepositoryStore.ORGANIZATION_EXT));
if( file != null){
file.delete();
}
......@@ -98,7 +109,7 @@ public class ImportOrganizationHandler extends AbstractHandler {
if(fis != null){
try {
fis.close() ;
} catch (IOException e) {
} catch (final IOException e) {
}
}
......@@ -106,7 +117,7 @@ public class ImportOrganizationHandler extends AbstractHandler {
}
});
} catch (Exception e) {
} catch (final Exception e) {
BonitaStudioLog.error(e) ;
} finally {
FileActionDialog.setThrowExceptionOnCancel(false);
......
......@@ -25,55 +25,56 @@ import org.eclipse.swt.widgets.Display;
public class FileActionDialog {
protected static boolean YES_TO_ALL = false;
protected static boolean NO_TO_ALL = false;
protected static boolean YES_NO_TO_ALL = false;
protected static boolean DISABLE_POPUP = false ; //Tests purpose
private static boolean answer;
private static int returnCode;
protected static boolean YES_TO_ALL = false;
protected static boolean NO_TO_ALL = false;
protected static boolean YES_NO_TO_ALL = false;
protected static boolean DISABLE_POPUP = false; //Tests purpose
private static boolean answer;
private static int returnCode;
private static boolean THROW_EXCEPTION_ON_CANCEL = false;
public static void setDisablePopup(boolean disablePopup) {
DISABLE_POPUP = disablePopup ;
}
public static void setDisablePopup(final boolean disablePopup) {
DISABLE_POPUP = disablePopup;
}
public static void setThrowExceptionOnCancel(boolean throwExceptionOnCancel){
THROW_EXCEPTION_ON_CANCEL = throwExceptionOnCancel;
public static void setThrowExceptionOnCancel(final boolean throwExceptionOnCancel){
THROW_EXCEPTION_ON_CANCEL = throwExceptionOnCancel;
}
public static boolean overwriteQuestion(final String fileName) {
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if(DISABLE_POPUP){
return true;
}else {
if(YES_NO_TO_ALL){
if(YES_TO_ALL){
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.overwriteTitle, Messages.bind(Messages.overwriteMessage, fileName)).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
}else{
Display.getDefault().syncExec(new Runnable() {
public static boolean overwriteQuestion(final String fileName) {
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if (DISABLE_POPUP) {
return true;
} else {
if (YES_NO_TO_ALL) {
if (YES_TO_ALL) {
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.overwriteTitle, Messages.bind(
Messages.overwriteMessage, fileName)).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
} else {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
answer = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.overwriteTitle,
......@@ -81,119 +82,122 @@ public class FileActionDialog {
}
}) ;
if(THROW_EXCEPTION_ON_CANCEL && !answer){
throw new CancellationException();
throw new CancellationException();
}
return answer ;
}
}
}
public static boolean getDisablePopup() {
return DISABLE_POPUP;
}
public static boolean confirmDeletionQuestion(final String fileName) {
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if(DISABLE_POPUP){
return true;
}else {
if(YES_NO_TO_ALL){
if(YES_TO_ALL){
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
Messages.bind(Messages.deleteConfirmationMsg, fileName)).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
}else{
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
answer = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
Messages.bind(Messages.deleteConfirmationMsg, fileName));
}
}) ;
return answer ;
}
}
}
public static boolean confirmDeletionQuestionWithCustomMessage(final String message){
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if(DISABLE_POPUP){
return true;
}else {
if(YES_NO_TO_ALL){
if(YES_TO_ALL){
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
message).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
}else{
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
String[] buttonLabels = {Messages.delete,IDialogConstants.CANCEL_LABEL};
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle, null, message, MessageDialog.QUESTION,buttonLabels , 0);
public static boolean getDisablePopup() {
return DISABLE_POPUP;
}
public static boolean confirmDeletionQuestion(final String fileName) {
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if (DISABLE_POPUP) {
return true;
} else {
if (YES_NO_TO_ALL) {
if (YES_TO_ALL) {
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
Messages.bind(Messages.deleteConfirmationMsg, fileName)).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
} else {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
answer = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
Messages.bind(Messages.deleteConfirmationMsg, fileName));
}
});
return answer;
}
}
}
public static boolean confirmDeletionQuestionWithCustomMessage(final String message) {
if (DISABLE_POPUP && NO_TO_ALL) {
return false;
} else if (DISABLE_POPUP) {
return true;
} else {
if (YES_NO_TO_ALL) {
if (YES_TO_ALL) {
return true;
}
if (NO_TO_ALL) {
return false;
}
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
returnCode = new YesNoToAllDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle,
message).open();
}
});
if (returnCode == YesNoToAllDialog.YES_TO_ALL) {
YES_TO_ALL = true;
}
if (returnCode == YesNoToAllDialog.NO_TO_ALL) {
NO_TO_ALL = true;
}
return returnCode == YesNoToAllDialog.YES || returnCode == YesNoToAllDialog.YES_TO_ALL;
} else {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final String[] buttonLabels = { Messages.delete, IDialogConstants.CANCEL_LABEL };
final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), Messages.deleteConfirmationTitle, null, message,
MessageDialog.QUESTION, buttonLabels, 0);
answer = dialog.open() == 0;
}
}) ;
return answer ;
}
}
}
public static void activateYesNoToAll(){
YES_NO_TO_ALL = true ;
}
public static void deactivateYesNoToAll(){
YES_NO_TO_ALL = false ;
YES_TO_ALL = false ;
NO_TO_ALL = false ;
}
public static void setNoToAll() {
NO_TO_ALL = true ;
YES_TO_ALL = false ;
}
}
});
return answer;
}
}
}
public static void activateYesNoToAll() {
YES_NO_TO_ALL = true;
}
public static void deactivateYesNoToAll() {
YES_NO_TO_ALL = false;
YES_TO_ALL = false;
NO_TO_ALL = false;
}
public static void setNoToAll() {
NO_TO_ALL = true;
YES_TO_ALL = false;
}
}
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