Commit ca67edd0 authored by Adrien's avatar Adrien Committed by Romain Bioteau
Browse files

feat(app) rename in open dialog (#392)

* possibility to rename a file from the open dialog
*  disable rename when several elements are selected
* if the file renamed is already open, then the editor is updated
* fix a small bug with the home page

closes [BS-16456](https://bonitasoft.atlassian.net/browse/BS-16456)
parent 301a2789
......@@ -24,11 +24,13 @@ Require-Bundle: org.bonitasoft.studio.common.repository;bundle-version="7.5.0",
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.bonitasoft.engine.business.application,
org.bonitasoft.engine.business.application.exporter,
org.bonitasoft.engine.business.application.xml
org.bonitasoft.engine.business.application.xml,
org.eclipse.ui.forms.editor
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.la,
org.bonitasoft.studio.la.core,
org.bonitasoft.studio.la.handler,
org.bonitasoft.studio.la.i18n,
org.bonitasoft.studio.la.repository,
org.bonitasoft.studio.la.ui.control,
org.bonitasoft.studio.la.ui.validator
......@@ -51,3 +51,5 @@ doNotShowMeAgain=Do not show me this dialog again
exportApplicationDescriptorTitle=Export
exportApplicationDescriptorMessage=You are about to export an application descriptor file.\nApplication(s) REST API extensions, pages and profiles are not part of the file. \nMake sure they are already installed before you import this file in the Portal.
unparsableApplicationFile=Unable to parse xml
rename=Rename
renameFile=Rename file
......@@ -25,7 +25,7 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.control.SelectApplicationDescriptorPage;
import org.bonitasoft.studio.la.ui.control.SelectRenameApplicationDescriptorPage;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
......@@ -42,7 +42,7 @@ public class OpenApplicationHandler {
private WizardBuilder<Stream<ApplicationFileStore>> createWizard(WizardBuilder<Stream<ApplicationFileStore>> builder,
RepositoryAccessor repositoryAccessor) {
SelectApplicationDescriptorPage selectApplicationDescriptorPage = new SelectApplicationDescriptorPage(
SelectRenameApplicationDescriptorPage selectApplicationDescriptorPage = new SelectRenameApplicationDescriptorPage(
repositoryAccessor);
return builder.withTitle(Messages.openExistingApplication)
.havingPage(newPage()
......
......@@ -71,6 +71,8 @@ public class Messages extends NLS {
public static String exportApplicationDescriptorTitle;
public static String exportApplicationDescriptorMessage;
public static String unparsableApplicationFile;
public static String rename;
public static String renameFile;
static {
NLS.initializeMessages("messages", Messages.class);
......
/**
* Copyright (C) 2017 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.la.ui.control;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.la.repository.ApplicationFileStore;
import org.bonitasoft.studio.la.repository.ApplicationRepositoryStore;
import org.bonitasoft.studio.la.ui.validator.ApplicationDescriptorFileNameValidator;
import org.bonitasoft.studio.ui.validator.InputValidatorWrapper;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Shell;
import com.google.common.base.Objects;
public class RenameApplicationDescriptorFileDialog {
public static boolean open(Shell shell, ApplicationRepositoryStore applicationRepositoryStore,
ApplicationFileStore applicationFileStore) {
String currentFileName = applicationFileStore.getDisplayName();
final InputDialog dialog = new InputDialog(shell, Messages.rename, Messages.renameFile,
currentFileName, new InputValidatorWrapper(
new ApplicationDescriptorFileNameValidator(applicationRepositoryStore, currentFileName)));
if (dialog.open() == Dialog.OK && !currentFileName.equals(stripXmlExtension(dialog.getValue()))) {
applicationFileStore.rename(stripXmlExtension(dialog.getValue()) + ".xml");
}
return !Objects.equal(currentFileName, applicationFileStore.getDisplayName());
}
private static String stripXmlExtension(String name) {
return name.toLowerCase().endsWith(".xml") ? name.replace(".xml", "") : name;
}
}
......@@ -44,9 +44,9 @@ public class SelectApplicationDescriptorPage implements ControlSupplier {
private static final int TABLE_WIDTH_HINT = 600;
private RepositoryAccessor repositoryAccessor;
protected RepositoryAccessor repositoryAccessor;
private TableViewer applicationsTableViewer;
protected TableViewer applicationsTableViewer;
public SelectApplicationDescriptorPage(RepositoryAccessor repositoryAccessor) {
this.repositoryAccessor = repositoryAccessor;
......
/**
* Copyright (C) 2017 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.la.ui.control;
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.ui.widget.ButtonWidget;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Shell;
public class SelectRenameApplicationDescriptorPage extends SelectApplicationDescriptorPage {
Shell currentShell;
public SelectRenameApplicationDescriptorPage(RepositoryAccessor repositoryAccessor) {
super(repositoryAccessor);
}
@Override
public Control createControl(Composite parent, IWizardContainer wizardContainer, DataBindingContext ctx) {
Composite mainComposite = new Composite(parent, SWT.NONE);
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
mainComposite.setLayout(GridLayoutFactory.fillDefaults().create());
super.createControl(mainComposite, wizardContainer, ctx);
currentShell = wizardContainer.getShell();
ButtonWidget renameButton = new ButtonWidget.Builder()
.alignLeft()
.withLabel(Messages.rename)
.onClick(this::rename)
.createIn(mainComposite);
renameButton.disable();
applicationsTableViewer.addSelectionChangedListener(e -> {
if (getSelection().count() == 1) {
renameButton.enable();
} else {
renameButton.disable();
}
});
return mainComposite;
}
public void rename(Event e) {
if (RenameApplicationDescriptorFileDialog.open(currentShell,
repositoryAccessor.getRepositoryStore(ApplicationRepositoryStore.class), getSelection().findFirst().get())) {
applicationsTableViewer.refresh();
}
}
}
......@@ -172,7 +172,7 @@ public class BotApplicationWorkbenchWindow extends AbstractBotMenu {
return new OpenApplicationWizardBot(bot, Messages.openExistingApplication);
}
public void newApplicationContainer() {
public void newApplicationDescriptorFile() {
bot.menu("Development").menu("Application Descriptor").menu("New...").click();
bot.waitUntil(Conditions.waitForEditor(IsInstanceOf.instanceOf(IEditorReference.class)));
}
......
......@@ -15,6 +15,7 @@
package org.bonitasoft.studio.swtbot.framework.la;
import org.bonitasoft.studio.la.i18n.Messages;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
......@@ -25,6 +26,15 @@ public class OpenApplicationWizardBot extends SelectApplicationWizardEditorBot {
super(bot, dialogTitle);
}
public OpenApplicationWizardBot rename(String newName) {
bot.button(Messages.rename).click();
bot.text().setText(newName);
final SWTBotShell activeShell = bot.activeShell();
bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(Conditions.shellCloses(activeShell));
return this;
}
/**
* click on open
*/
......
......@@ -19,7 +19,7 @@ import static org.junit.Assert.assertEquals;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.handler.NewApplicationHandler;
import org.bonitasoft.studio.swtbot.framework.application.BotApplicationWorkbenchWindow;
import org.bonitasoft.studio.swtbot.framework.la.DeleteApplicationWizardBot;
import org.bonitasoft.studio.swtbot.framework.la.OpenApplicationWizardBot;
import org.bonitasoft.studio.swtbot.framework.rule.SWTGefBotRule;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot;
......@@ -71,18 +71,29 @@ public class OpenExistingApplicationIT {
deleteApplications(workBenchBot);
}
@Test
public void should_rename_file_using_open_menu() {
final BotApplicationWorkbenchWindow workBenchBot = new BotApplicationWorkbenchWindow(bot);
workBenchBot.newApplicationDescriptorFile();
OpenApplicationWizardBot openApplicationWizardBot = workBenchBot.openApplication();
openApplicationWizardBot.select(NewApplicationHandler.DEFAULT_FILE_NAME + ".xml");
openApplicationWizardBot.rename("custom_name").select("custom_name.xml").finish();
workBenchBot.deleteApplicationDescriptor()
.select("custom_name.xml")
.delete();
}
private void deleteApplications(BotApplicationWorkbenchWindow workBenchBot) {
final DeleteApplicationWizardBot deleteApplicationBot = workBenchBot.deleteApplicationDescriptor();
deleteApplicationBot
workBenchBot.deleteApplicationDescriptor()
.select(NewApplicationHandler.DEFAULT_FILE_NAME + ".xml", NewApplicationHandler.DEFAULT_FILE_NAME + "1.xml")
.delete();
}
private void createApplications(BotApplicationWorkbenchWindow workBenchBot) {
workBenchBot.newApplicationContainer();
workBenchBot.newApplicationDescriptorFile();
bot.activeEditor().close();
workBenchBot.newApplicationContainer();
workBenchBot.newApplicationDescriptorFile();
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