Commit 1b863bab authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub

fix(applicationEditor) cache custom pages in provider (#2551)

Closes STUDIO-3738
Signed-off-by: default avatarRomain Bioteau <romain.bioteau@bonitasoft.com>
parent 408d11ae
......@@ -40,6 +40,7 @@ import org.bonitasoft.studio.engine.operation.ApplicationURLBuilder;
import org.bonitasoft.studio.la.LivingApplicationPlugin;
import org.bonitasoft.studio.la.application.core.ApplicationDependencyResolver;
import org.bonitasoft.studio.la.application.handler.DeployApplicationHandler;
import org.bonitasoft.studio.la.application.ui.editor.customPage.CustomPageProvider;
import org.bonitasoft.studio.la.application.ui.editor.listener.CloneApplicationDescriptorListener;
import org.bonitasoft.studio.la.application.ui.editor.listener.DeleteApplicationDescriptorListener;
import org.bonitasoft.studio.la.i18n.Messages;
......@@ -78,8 +79,10 @@ public class ApplicationDescriptorControl {
private Section control;
private ApplicationNode application;
public ApplicationDescriptorControl(Section applicationSection, ApplicationNode application,
ApplicationFormPage formPage) {
public ApplicationDescriptorControl(Section applicationSection,
ApplicationNode application,
ApplicationFormPage formPage,
CustomPageProvider customPageProvider) {
this.control = applicationSection;
this.application = application;
......@@ -169,8 +172,7 @@ public class ApplicationDescriptorControl {
formPage,
application,
toolkit,
formPage.getRepositoryAccessor().getRepositoryStore(WebPageRepositoryStore.class),
formPage.getRepositoryAccessor().getRepositoryStore(ThemeRepositoryStore.class),
customPageProvider,
homePageObservable);
navigationSection.setClient(applicationNavigation);
......
......@@ -18,13 +18,18 @@ import javax.xml.bind.JAXBException;
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.designer.core.repository.WebPageRepositoryStore;
import org.bonitasoft.studio.la.application.ui.editor.customPage.CustomPageProvider;
import org.bonitasoft.studio.la.application.ui.editor.listener.AddApplicationDescriptorListener;
import org.bonitasoft.studio.la.i18n.Messages;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants;
import org.bonitasoft.studio.preferences.BonitaThemeConstants;
import org.bonitasoft.studio.preferences.PreferenceUtil;
import org.bonitasoft.studio.theme.ThemeRepositoryStore;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
......@@ -43,10 +48,16 @@ public class ApplicationFormPart extends AbstractFormPart {
private FormToolkit toolkit;
private ApplicationFormPage formPage;
private List<ApplicationDescriptorControl> applicationDescriptorControls = new ArrayList<>();
protected CustomPageProvider customPageProvider;
public ApplicationFormPart(Composite parent, ApplicationFormPage formPage) {
ApplicationNodeContainer workingCopy = formPage.getWorkingCopy();
this.formPage = formPage;
RepositoryAccessor repositoryAccessor = formPage.getRepositoryAccessor();
this.customPageProvider = new CustomPageProvider(
repositoryAccessor.getRepositoryStore(WebPageRepositoryStore.class),
repositoryAccessor.getRepositoryStore(ThemeRepositoryStore.class));
customPageProvider.init();
toolkit = formPage.getToolkit();
if (workingCopy.getApplications().isEmpty()) {
createNoApplicationsComposite(parent, formPage);
......@@ -75,7 +86,8 @@ public class ApplicationFormPart extends AbstractFormPart {
return new ApplicationDescriptorControl(
section,
application,
formPage);
formPage,
customPageProvider);
}
public void addApplicationToForm(Composite parent, ApplicationNode application) {
......@@ -84,7 +96,8 @@ public class ApplicationFormPart extends AbstractFormPart {
ApplicationDescriptorControl applicationDescriptorControl = new ApplicationDescriptorControl(
section,
application,
formPage);
formPage,
customPageProvider);
applicationDescriptorControls.add(applicationDescriptorControl);
}
......@@ -134,7 +147,8 @@ public class ApplicationFormPart extends AbstractFormPart {
public void expendApplication(List<String> applicationTokens) {
applicationDescriptorControls
.stream()
.filter(applicationControl -> applicationTokens.contains(applicationControl.getTokenObservable().getValue()))
.filter(applicationControl -> applicationTokens
.contains(applicationControl.getTokenObservable().getValue()))
.forEach(applicationControl -> applicationControl.getControl().setExpanded(true));
if (applicationTokens.isEmpty()) {
applicationDescriptorControls
......@@ -153,4 +167,12 @@ public class ApplicationFormPart extends AbstractFormPart {
.collect(Collectors.toList());
}
@Override
public void dispose() {
if (customPageProvider != null) {
customPageProvider.dispose();
}
super.dispose();
}
}
......@@ -89,8 +89,7 @@ public class ApplicationNavigation extends Composite {
ApplicationFormPage formPage,
ApplicationNode applicationNode,
FormToolkit toolkit,
WebPageRepositoryStore webPageStore,
ThemeRepositoryStore themeStore,
CustomPageProvider customPageProvider,
IObservableValue<String> homePageObservable) {
super(parent, SWT.NONE);
toolkit.adapt(this);
......@@ -100,7 +99,7 @@ public class ApplicationNavigation extends Composite {
this.updateApplicationNodeOperation = new UpdateApplicationNodeOperation(applicationNode);
this.toolkit = toolkit;
this.homePageObservable = homePageObservable;
customPageProvider = new CustomPageProvider(webPageStore, themeStore);
this.customPageProvider = customPageProvider;
this.ctx = new DataBindingContext();
menuAndOrphanList = toNavigationConverter.toNavigationPageNodeList(applicationNode);
......
......@@ -32,6 +32,7 @@ public class ApplicationEditorProviders {
this.layoutProposalProvider = new LayoutProposalProvider(customPageProvider, true);
this.themeProposalProvider = new ThemeProposalProvider(customPageProvider, true);
this.profileProposalProvider = createProfileProposalProvider(repositoryAccessor);
this.customPageProvider.init();
profileProposalProvider.setFiltering(true);
}
......@@ -58,5 +59,6 @@ public class ApplicationEditorProviders {
public void dispose() {
layoutProposalProvider.dispose();
themeProposalProvider.dispose();
customPageProvider.dispose();
}
}
......@@ -14,14 +14,22 @@ import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.designer.core.repository.WebPageFileStore;
import org.bonitasoft.studio.designer.core.repository.WebPageRepositoryStore;
import org.bonitasoft.studio.la.application.core.BonitaPagesRegistry;
import org.bonitasoft.studio.theme.ThemeRepositoryStore;
import org.bonitasoft.studio.ui.converter.ConverterBuilder;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
public class CustomPageProvider {
public class CustomPageProvider implements IResourceChangeListener {
public static final List<CustomPageDescriptor> DEFAULT_THEMES = new ArrayList<>();
static {
......@@ -31,6 +39,9 @@ public class CustomPageProvider {
private final WebPageRepositoryStore webPageStore;
private ThemeRepositoryStore themeStore;
private List<CustomPageDescriptor> pages;
private List<CustomPageDescriptor> layouts;
private List<CustomPageDescriptor> themes;
public CustomPageProvider(WebPageRepositoryStore store, ThemeRepositoryStore themeStore) {
this.webPageStore = store;
......@@ -38,32 +49,36 @@ public class CustomPageProvider {
}
public List<CustomPageDescriptor> getLayouts() {
final List<CustomPageDescriptor> layouts = new ArrayList<>();
layouts.add(CustomPageDescriptor.DEFAULT_LAYOUT);
webPageStore.getChildren()
.stream()
.filter(webPageFileStore -> Objects.equals(webPageFileStore.getType(), WebPageFileStore.LAYOUT_TYPE))
.map(fileStore -> new CustomPageDescriptor(
CustomPageDescriptor.CUSTOMPAGE_PREFIX + fileStore.getCustomPageName(),
fileStore.getDisplayName(), fileStore.getDescription()))
.forEach(layouts::add);
layouts.add(CustomPageDescriptor.LEGACY_DEFAULT_LAYOUT);
if (layouts == null) {
layouts = new ArrayList<>();
layouts.add(CustomPageDescriptor.DEFAULT_LAYOUT);
webPageStore.getChildren()
.stream()
.filter(webPageFileStore -> Objects.equals(webPageFileStore.getType(),
WebPageFileStore.LAYOUT_TYPE))
.map(fileStore -> new CustomPageDescriptor(
CustomPageDescriptor.CUSTOMPAGE_PREFIX + fileStore.getCustomPageName(),
fileStore.getDisplayName(), fileStore.getDescription()))
.forEach(layouts::add);
layouts.add(CustomPageDescriptor.LEGACY_DEFAULT_LAYOUT);
}
return layouts;
}
public List<CustomPageDescriptor> getApplicationPages() {
final List<CustomPageDescriptor> pages = new ArrayList<>();
webPageStore.getChildren()
.stream()
.filter(webPageFileStore -> Objects.equals(webPageFileStore.getType(), WebPageFileStore.PAGE_TYPE))
.map(fileStore -> new CustomPageDescriptor(
CustomPageDescriptor.CUSTOMPAGE_PREFIX + fileStore.getCustomPageName(),
fileStore.getDisplayName(), fileStore.getDescription()))
.forEach(pages::add);
BonitaPagesRegistry.getInstance().getCustomPages().stream()
.map(p -> new CustomPageDescriptor(p.getPageId(), p.getDisplayName(), p.getDescription()))
.forEach(pages::add);
if (pages == null) {
pages = new ArrayList<>();
webPageStore.getChildren()
.stream()
.filter(webPageFileStore -> Objects.equals(webPageFileStore.getType(), WebPageFileStore.PAGE_TYPE))
.map(fileStore -> new CustomPageDescriptor(
CustomPageDescriptor.CUSTOMPAGE_PREFIX + fileStore.getCustomPageName(),
fileStore.getDisplayName(), fileStore.getDescription()))
.forEach(pages::add);
BonitaPagesRegistry.getInstance().getCustomPages().stream()
.map(p -> new CustomPageDescriptor(p.getPageId(), p.getDisplayName(), p.getDescription()))
.forEach(pages::add);
}
return pages;
}
......@@ -104,7 +119,8 @@ public class CustomPageProvider {
.create();
}
public static IConverter<String, String> getCustomPageDisplayNameConverter(Collection<CustomPageDescriptor> layouts) {
public static IConverter<String, String> getCustomPageDisplayNameConverter(
Collection<CustomPageDescriptor> layouts) {
return ConverterBuilder.<String, String> newConverter()
.fromType(String.class)
.toType(String.class)
......@@ -126,22 +142,59 @@ public class CustomPageProvider {
}
public Collection<CustomPageDescriptor> getThemes() {
final List<CustomPageDescriptor> pages = new ArrayList<>();
themeStore.getChildren()
.stream()
.filter(Objects::nonNull)
.filter(fileStore -> fileStore.getPageId() != null)
.map(fileStore -> new CustomPageDescriptor(
fileStore.getPageId(),
fileStore.getPageDisplayName(),
fileStore.getDescription()))
.forEach(pages::add);
pages.addAll(DEFAULT_THEMES);
return pages;
if (themes == null) {
themes = new ArrayList<>();
themeStore.getChildren()
.stream()
.filter(Objects::nonNull)
.filter(fileStore -> fileStore.getPageId() != null)
.map(fileStore -> new CustomPageDescriptor(
fileStore.getPageId(),
fileStore.getPageDisplayName(),
fileStore.getDescription()))
.forEach(themes::add);
themes.addAll(DEFAULT_THEMES);
}
return themes;
}
public ThemeRepositoryStore getThemeStore() {
return themeStore;
}
@Override
public void resourceChanged(IResourceChangeEvent event) {
try {
event.getDelta().accept(new IResourceDeltaVisitor() {
@Override
public boolean visit(IResourceDelta delta) throws CoreException {
IResource resource = delta.getResource();
if (resource != null && resource.getLocation() != null
&& webPageStore.getResource().getLocation().isPrefixOf(resource.getLocation())) {
pages = null;
layouts = null;
return false;
}
if (resource != null && resource.getLocation() != null
&& themeStore.getResource().getLocation().isPrefixOf(resource.getLocation())) {
themes = null;
return false;
}
return true;
}
});
} catch (CoreException e) {
BonitaStudioLog.error(e);
}
}
public void dispose() {
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
}
public void init() {
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
}
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