Commit 025311b8 authored by Adrien's avatar Adrien Committed by GitHub
Browse files

feat(app) add/delete descriptors (#357)

* feat(app) add/delete descriptors

* add an application descriptor to a container from the overview
* delete an application descriptor from the overview
* you only have to provide filename to create a container
* if you open a container without descriptors, then a big icon appear in
the middle of the form to create one

closes[BS-16338](https://bonitasoft.atlassian.net/browse/BS-16338)
parent 2a56b846
applicationStoreName=Applications
createNewApplicationDescriptor=Create a new Application Descriptor
create=Create
newApplicationDescriptorTitle=Create a new Application Descriptor
newApplicationDescription=Fill the basic informations for a first application to create a new Application Descriptor
newApplicationDescriptorTitle=Create a new Application Descriptor Container
newApplicationDescription=Choose a filename to create a new application descriptor container
applicationTokenMessage=A unique identifier used as url endpoint for the application (../apps/<url>)
applicationToken=Application Token
version=Version
......@@ -44,3 +43,6 @@ invalidFileName='%s' is not a valid filename
exportFailedTitle=Export failed
exportOperation=Export operation
exporting=Exporting %s...
deleteDescriptor='%s' application descriptor will be removed from this file and deleted from the portal.\nConfirm deletion ?
deleteDescriptorDone='%s' has been deleted
deleteContainer=Delete the file %s, with all its application descriptors
\ No newline at end of file
......@@ -15,7 +15,6 @@
package org.bonitasoft.studio.la.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.bonitasoft.engine.business.application.xml.ApplicationNodeBuilder.newApplication;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.notNull;
......@@ -27,8 +26,6 @@ import static org.mockito.Mockito.when;
import java.util.Optional;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.business.application.xml.ApplicationNodeContainer;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
......@@ -38,7 +35,6 @@ import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.bonitasoft.studio.ui.wizard.WizardPageBuilder;
import org.eclipse.swt.widgets.Shell;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
public class NewApplicationHandlerTest {
......@@ -64,7 +60,7 @@ public class NewApplicationHandlerTest {
final WizardBuilder<ApplicationFileStore> builder = spy(WizardBuilder.newWizard());
newApplicationHandler.createWizard(builder, repositoryAccessor);
verify(builder).withTitle(Messages.createNewApplicationDescriptor);
verify(builder).withTitle(Messages.newApplicationDescriptorTitle);
verify(builder).havingPage(notNull(WizardPageBuilder.class));
verify(builder).onFinish(notNull(FinishHandler.class));
}
......@@ -78,14 +74,10 @@ public class NewApplicationHandlerTest {
when(applicationStore.createRepositoryFileStore("testAppToken.xml")).thenReturn(applicationFileStore);
when(repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class)).thenReturn(applicationStore);
final ApplicationNode applicationNode = newApplication("testAppToken", "My App Display Name", "0.1").create();
final Optional<ApplicationFileStore> fileStore = newApplicationHandler.createApplicationFileStore(
applicationNode, repositoryAccessor, "testAppToken");
final Optional<ApplicationFileStore> fileStore = newApplicationHandler.createApplicationFileStore(repositoryAccessor,
"testAppToken");
assertThat(fileStore).isPresent();
final ArgumentCaptor<ApplicationNodeContainer> captor = ArgumentCaptor.forClass(ApplicationNodeContainer.class);
verify(applicationFileStore).save(captor.capture());
assertThat(captor.getValue().getApplications()).extracting("token").contains("testAppToken");
}
}
......@@ -14,14 +14,12 @@
*/
package org.bonitasoft.studio.la.handler;
import static org.bonitasoft.engine.business.application.xml.ApplicationNodeBuilder.newApplication;
import static org.bonitasoft.engine.business.application.xml.ApplicationNodeBuilder.newApplicationContainer;
import static org.bonitasoft.studio.ui.wizard.WizardBuilder.newWizard;
import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
import java.util.Optional;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.engine.business.application.xml.ApplicationNodeContainer;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
......@@ -36,9 +34,6 @@ import org.eclipse.swt.widgets.Shell;
public class NewApplicationHandler {
private static final String DEFAULT_PROFILE = "User";
private static final String DEFAULT_THEME = "custompage_bootstrapdefaulttheme";
private static final String DEFAULT_LAYOUT = "custompage_defaultlayout";
public static final String XML_EXTENSION = ".xml";
@Execute
......@@ -50,25 +45,20 @@ public class NewApplicationHandler {
protected WizardBuilder<ApplicationFileStore> createWizard(WizardBuilder<ApplicationFileStore> builder,
RepositoryAccessor repositoryAccessor) {
final ApplicationNode applicationNode = newApplication("myApp", "My App", "1.0").create();
applicationNode.setProfile(DEFAULT_PROFILE);
applicationNode.setLayout(DEFAULT_LAYOUT);
applicationNode.setTheme(DEFAULT_THEME);
final NewApplicationPage newApplicationPage = new NewApplicationPage(applicationNode, repositoryAccessor);
final NewApplicationPage newApplicationPage = new NewApplicationPage(repositoryAccessor);
return builder
.withTitle(Messages.createNewApplicationDescriptor)
.withSize(SWT.DEFAULT, 480)
.withTitle(Messages.newApplicationDescriptorTitle)
.withSize(SWT.DEFAULT, 235)
.havingPage(newPage()
.withTitle(Messages.newApplicationDescriptorTitle)
.withDescription(Messages.newApplicationDescription)
.withControl(newApplicationPage))
.onFinish(container -> createApplicationFileStore(applicationNode, repositoryAccessor,
newApplicationPage.getFilename()));
.onFinish(container -> createApplicationFileStore(repositoryAccessor, newApplicationPage.getFilename()));
}
protected Optional<ApplicationFileStore> createApplicationFileStore(ApplicationNode applicationNode,
RepositoryAccessor repositoryAccessor, String fileName) {
protected Optional<ApplicationFileStore> createApplicationFileStore(RepositoryAccessor repositoryAccessor,
String fileName) {
final ApplicationRepositoryStore repositoryStore = repositoryAccessor
.getRepositoryStore(ApplicationRepositoryStore.class);
......@@ -77,7 +67,6 @@ public class NewApplicationHandler {
final Optional<ApplicationFileStore> fileStore = Optional.ofNullable(repositoryStore
.createRepositoryFileStore(String.format("%s%s", fileNameTrimed, XML_EXTENSION)));
final ApplicationNodeContainer nodeContainer = newApplicationContainer().create();
nodeContainer.addApplication(applicationNode);
fileStore.ifPresent(file -> file.save(nodeContainer));
return fileStore;
}
......
......@@ -20,7 +20,6 @@ public class Messages extends NLS {
public static String url;
public static String applicationStoreName;
public static String createNewApplicationDescriptor;
public static String create;
public static String newApplicationDescriptorTitle;
public static String newApplicationDescription;
......@@ -64,6 +63,9 @@ public class Messages extends NLS {
public static String exportFailedTitle;
public static String exportOperation;
public static String exporting;
public static String deleteDescriptor;
public static String deleteDescriptorDone;
public static String deleteContainer;
static {
NLS.initializeMessages("messages", Messages.class);
......
......@@ -16,15 +16,10 @@ package org.bonitasoft.studio.la.ui.control;
import static org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory.updateValueStrategy;
import org.bonitasoft.engine.business.application.xml.ApplicationNode;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.validator.ApplicationDescriptorFileNameValidator;
import org.bonitasoft.studio.la.ui.validator.ApplicationTokenUnicityValidator;
import org.bonitasoft.studio.ui.validator.EmptyInputValidator;
import org.bonitasoft.studio.ui.validator.MultiValidator;
import org.bonitasoft.studio.ui.validator.RegExpValidator;
import org.bonitasoft.studio.ui.widget.TextWidget;
import org.bonitasoft.studio.ui.wizard.ControlSupplier;
import org.eclipse.core.databinding.DataBindingContext;
......@@ -39,12 +34,10 @@ import org.eclipse.swt.widgets.Control;
public class NewApplicationPage implements ControlSupplier {
public static final String DEFAULT_FILE_NAME = "applicationDescriptor";
private final ApplicationNode applicationNode;
private final RepositoryAccessor repositoryAccessor;
private String filename = DEFAULT_FILE_NAME;
public NewApplicationPage(ApplicationNode applicationNode, RepositoryAccessor repositoryAccessor) {
this.applicationNode = applicationNode;
public NewApplicationPage(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;
}
......@@ -67,46 +60,6 @@ public class NewApplicationPage implements ControlSupplier {
repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class))))
.createIn(composite);
new TextWidget.Builder()
.withLabel(Messages.applicationToken)
.withMessage(Messages.applicationTokenMessage)
.labelAbove()
.fill()
.grabHorizontalSpace()
.bindTo(PojoObservables.observeValue(applicationNode, "token"))
.inContext(ctx)
.withTargetToModelStrategy(updateValueStrategy()
.withValidator(new MultiValidator.Builder().havingValidators(
new EmptyInputValidator.Builder().withMessage(Messages.required),
new RegExpValidator.Builder().matches("^[a-zA-Z0-9]+$")
.withMessage(Messages.alphaNumericOnly),
new ApplicationTokenUnicityValidator.Builder(repositoryAccessor))))
.createIn(composite);
new TextWidget.Builder()
.withLabel(Messages.displayName)
.withMessage(Messages.displayNameMessage)
.labelAbove()
.fill()
.grabHorizontalSpace()
.bindTo(PojoObservables.observeValue(applicationNode, "displayName"))
.inContext(ctx)
.withTargetToModelStrategy(updateValueStrategy()
.withValidator(
new EmptyInputValidator.Builder().withMessage(Messages.required).create()))
.createIn(composite);
new TextWidget.Builder()
.withLabel(Messages.version)
.labelAbove()
.widthHint(150)
.grabHorizontalSpace()
.bindTo(PojoObservables.observeValue(applicationNode, "version"))
.inContext(ctx)
.withTargetToModelStrategy(updateValueStrategy()
.withValidator(new EmptyInputValidator.Builder().withMessage(Messages.required).create()))
.createIn(composite);
return composite;
}
......
......@@ -220,7 +220,6 @@ public class TextWidget extends EditableControlWidget {
text = newText(textContainer);
text.setData(SWTBOT_WIDGET_ID_KEY, id);
text.setEnabled(!readOnly);
configureBackground(text);
text.addListener(SWT.FocusIn, event -> redraw(textContainer));
......@@ -375,7 +374,6 @@ public class TextWidget extends EditableControlWidget {
private void updateEditableState(boolean editable) {
readOnly = !editable;
text.setEnabled(!readOnly);
configureBackground(text);
configureBackground(text.getParent());
editing = editable;
......@@ -398,13 +396,10 @@ public class TextWidget extends EditableControlWidget {
if (toolkit.isPresent()) {
toolkit.get().adapt(control, true, true);
}
if (!readOnly) {
control.setEnabled(true);
control.setBackground(whiteColor);
} else {
control.setBackground(backgroundColor);
control.setEnabled(false);
}
control.setBackground(readOnly ? backgroundColor : whiteColor);
control.setEnabled(!readOnly);
}
public TextWidget setText(String text) {
......
......@@ -171,9 +171,9 @@ public class BotApplicationWorkbenchWindow extends AbstractBotMenu {
return new OpenApplicationWizardBot(bot, Messages.openExistingApplication);
}
public NewApplicationWizardBot newApplication() {
public NewApplicationWizardBot newApplicationContainer() {
bot.menu("Development").menu("Application Descriptor").menu("New...").click();
return new NewApplicationWizardBot(bot, Messages.createNewApplicationDescriptor);
return new NewApplicationWizardBot(bot, Messages.newApplicationDescriptorTitle);
}
public DeleteApplicationWizardBot deleteApplicationDescriptor() {
......
......@@ -31,20 +31,6 @@ public class NewApplicationWizardBot extends BotWizardDialog {
return this;
}
public NewApplicationWizardBot withToken(String token) {
bot.textWithLabel(Messages.applicationToken).setText(token);
return this;
}
public NewApplicationWizardBot withDisplayName(String displayName) {
bot.textWithLabel(Messages.displayName).setText(displayName);
return this;
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.swtbot.framework.BotWizardDialog#finish()
*/
@Override
public void finish() {
bot.waitUntil(Conditions.widgetIsEnabled(bot.button(Messages.create)));
......
......@@ -39,13 +39,13 @@ public class OpenExistingApplicationIT {
final BotApplicationWorkbenchWindow workBenchBot = new BotApplicationWorkbenchWindow(bot);
createApplications(workBenchBot);
workBenchBot.openApplication().select("file1.xml ../apps/app1").finish();
workBenchBot.openApplication().select("file1.xml").finish();
final SWTBotEditor app1Editor = bot.activeEditor();
assertEquals("file1.xml", app1Editor.getTitle());
app1Editor.close();
workBenchBot.openApplication()
.select("file1.xml ../apps/app1", "file2.xml ../apps/app2")
.select("file1.xml", "file2.xml")
.finish();
assertEquals(2, bot.editors().size());
......@@ -54,22 +54,18 @@ public class OpenExistingApplicationIT {
private void deleteApplications(BotApplicationWorkbenchWindow workBenchBot) {
final DeleteApplicationWizardBot deleteApplicationBot = workBenchBot.deleteApplicationDescriptor();
deleteApplicationBot.select("file1.xml ../apps/app1", "file2.xml ../apps/app2")
deleteApplicationBot.select("file1.xml", "file2.xml")
.delete();
}
private void createApplications(BotApplicationWorkbenchWindow workBenchBot) {
workBenchBot.newApplication()
workBenchBot.newApplicationContainer()
.withFilename("file1")
.withToken("app1")
.withDisplayName("My First App")
.finish();
bot.activeEditor().close();
workBenchBot.newApplication()
workBenchBot.newApplicationContainer()
.withFilename("file2")
.withToken("app2")
.withDisplayName("My Second App")
.finish();
bot.activeEditor().close();
}
......
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