diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectPropertiesPanel.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectPropertiesPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..ea44572fa5843a2eeb6cbd667b3fddf68b30e320 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectPropertiesPanel.java @@ -0,0 +1,97 @@ +/* + * Copyright 2009 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.client.web.client.application; + +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.util.LinkedHashMap; +import java.util.Map; + +import com.extjs.gxt.ui.client.widget.ContentPanel; + +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.PropertyValueRenderers; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.property.PropertyGrid; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.MultilineHTML; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMessageProvider; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Person; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; + +/** + * {@link ContentPanel} containing project properties. + * + * @author Piotr Buczek + */ +public class ProjectPropertiesPanel extends ContentPanel +{ + public static final String PROPERTIES_ID_PREFIX = + GenericConstants.ID_PREFIX + "project-properties-section_"; + + private final Project project; + + private final IViewContext<?> viewContext; + + public ProjectPropertiesPanel(final Project project, final IViewContext<?> viewContext) + { + setHeading("Project Properties"); + this.project = project; + this.viewContext = viewContext; + final PropertyGrid propertyGrid = createPropertyGrid(); + add(propertyGrid); + } + + private final PropertyGrid createPropertyGrid() + { + final Map<String, Object> properties = createProperties(viewContext); + final PropertyGrid propertyGrid = new PropertyGrid(viewContext, properties.size()); + propertyGrid.getElement().setId(PROPERTIES_ID_PREFIX + project.getIdentifier()); + propertyGrid.registerPropertyValueRenderer(Person.class, PropertyValueRenderers + .createPersonPropertyValueRenderer(viewContext)); + propertyGrid.setProperties(properties); + return propertyGrid; + } + + private final Map<String, Object> createProperties(final IMessageProvider messageProvider) + { + final Map<String, Object> properties = new LinkedHashMap<String, Object>(); + + properties.put(messageProvider.getMessage(Dict.PROJECT), project.getIdentifier()); + properties.put(messageProvider.getMessage(Dict.REGISTRATOR), project.getRegistrator()); + properties.put(messageProvider.getMessage(Dict.REGISTRATION_DATE), project + .getRegistrationDate()); + // show description in multiple lines (renderer would need to be assigned to String.class) + final String description = + project.getDescription() == null ? null : new MultilineHTML(project + .getDescription()).toString(); + properties.put(messageProvider.getMessage(Dict.DESCRIPTION), description); + + return properties; + } +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectViewer.java index e12a58225d5f856236a45af77071fb1d8dc08442..8304ccd6823f3e6b4ef02a13ff0ae7fc12fdc83c 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectViewer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ProjectViewer.java @@ -16,25 +16,36 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application; +import java.util.Set; + import com.extjs.gxt.ui.client.Style.LayoutRegion; import com.extjs.gxt.ui.client.Style.Scroll; +import com.extjs.gxt.ui.client.widget.Component; +import com.extjs.gxt.ui.client.widget.ContentPanel; import com.extjs.gxt.ui.client.widget.layout.BorderLayout; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.CompositeDatabaseModificationObserver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.DatabaseModificationAwareComponent; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.framework.IDatabaseModificationObserver; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.AbstractViewer; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.BorderLayoutDataFactory; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.project.ProjectGrid; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.project.ProjectListDeletionConfirmationDialog; +import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind.ObjectKind; /** * Presents details of the project. * * @author Izabela Adamczyk + * @author Piotr Buczek */ -public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder> +public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder> implements + IDatabaseModificationObserver { private static final String PREFIX = "project-viewer_"; @@ -47,29 +58,39 @@ public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder // cannot use 'originalData' because Project does not implement IEntityInformationHolder private Project originalProject; - private final CompositeDatabaseModificationObserver modificationObserver; - public static DatabaseModificationAwareComponent create( final IViewContext<ICommonClientServiceAsync> viewContext, final TechId projectId) { ProjectViewer viewer = new ProjectViewer(viewContext, projectId); - return new DatabaseModificationAwareComponent(viewer, viewer.modificationObserver); + return new DatabaseModificationAwareComponent(viewer, viewer); } private ProjectViewer(final IViewContext<ICommonClientServiceAsync> viewContext, final TechId projectId) { super(viewContext, createId(projectId)); - setLayout(new BorderLayout()); this.projectId = projectId; - this.modificationObserver = new CompositeDatabaseModificationObserver(); this.viewContext = viewContext; + setLayout(new BorderLayout()); + extendToolBar(); reloadAllData(); } + private void extendToolBar() + { + addToolBarButton(createDeleteButton(new IDelegatedAction() + { + public void execute() + { + new ProjectListDeletionConfirmationDialog(viewContext, originalProject, + createDeletionCallback()).show(); + } + })); + } + private void reloadAllData() { - reloadData(new ProjectInfoCallback(viewContext, this, modificationObserver)); + reloadData(new ProjectInfoCallback(viewContext, this)); } public static String createId(final TechId projectId) @@ -94,15 +115,11 @@ public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder { private final ProjectViewer viewer; - private final CompositeDatabaseModificationObserver modificationObserver; - private ProjectInfoCallback(final IViewContext<ICommonClientServiceAsync> viewContext, - final ProjectViewer viewer, - final CompositeDatabaseModificationObserver modificationObserver) + final ProjectViewer viewer) { super(viewContext); this.viewer = viewer; - this.modificationObserver = modificationObserver; } @Override @@ -110,25 +127,54 @@ public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder { viewer.updateOriginalProject(result); viewer.removeAll(); - viewer.setScrollMode(Scroll.AUTO); - AttachmentVersionsSection<Project> attachmentsSection = - viewer.createAttachmentsSection(result); - viewer.add(attachmentsSection, createBorderLayoutData(LayoutRegion.NORTH)); - modificationObserver.addObserver(attachmentsSection.getDatabaseModificationObserver()); + // Top panel + final Component topPanel = viewer.createTopPanel(result); + viewer.add(topPanel, BorderLayoutDataFactory.create(LayoutRegion.NORTH, 150)); + // Central panel + final Component centerPanel = viewer.createCenterPanel(result); + viewer.add(centerPanel, BorderLayoutDataFactory.create(LayoutRegion.CENTER)); + viewer.layout(); } + + @Override + public void finishOnFailure(Throwable caught) + { + viewer.setupRemovedEntityView(); + } } private void updateOriginalProject(Project result) { this.originalProject = result; - editButton.enable(); - updateTitle(); + updateTitle(getOriginalDataDescription()); + setToolBarButtonsEnabled(true); + } + + @Override + public void setupRemovedEntityView() + { + removeAll(); + updateTitle(getOriginalDataDescription() + " does not exist any more."); + setToolBarButtonsEnabled(false); + } + + public Component createCenterPanel(Project result) + { + final ContentPanel panel = createAttachmentsSection(result); + return panel; + } + + public Component createTopPanel(Project result) + { + final ContentPanel panel = new ProjectPropertiesPanel(result, viewContext); + panel.setScrollMode(Scroll.AUTOY); + return panel; } - private void updateTitle() + private String getOriginalDataDescription() { - updateTitle(viewContext.getMessage(Dict.PROJECT) + " " + originalProject.getIdentifier()); + return viewContext.getMessage(Dict.PROJECT) + " " + originalProject.getIdentifier(); } @Override @@ -137,4 +183,14 @@ public final class ProjectViewer extends AbstractViewer<IEntityInformationHolder assert originalProject != null; ProjectGrid.showEntityViewer(originalProject, true, viewContext); } + + public void update(Set<DatabaseModificationKind> observedModifications) + { + reloadAllData(); + } + + public DatabaseModificationKind[] getRelevantModifications() + { + return DatabaseModificationKind.any(ObjectKind.PROJECT); + } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java index 2fc52542b3a35294dc985bb364fe83043ec2e678..63c4e2f035e26cc48461c72d84fd4f7a530c4ded 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java @@ -193,7 +193,7 @@ public abstract class AbstractViewer<D extends IEntityInformationHolder> extends setToolBarButtonsEnabled(false); } - private void setToolBarButtonsEnabled(boolean enabled) + protected void setToolBarButtonsEnabled(boolean enabled) { for (Button button : toolBarButtons) { @@ -203,8 +203,8 @@ public abstract class AbstractViewer<D extends IEntityInformationHolder> extends private String getOriginalDataDescription() { - return originalData.getEntityKind().getDescription() + " " + originalData.getCode() + "(" - + originalData.getEntityType().getCode() + ")"; + return originalData.getEntityKind().getDescription() + " " + originalData.getCode() + " [" + + originalData.getEntityType().getCode() + "]"; } protected final static BorderLayoutData createLeftBorderLayoutData() diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/project/ProjectListDeletionConfirmationDialog.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/project/ProjectListDeletionConfirmationDialog.java index 899798168348b7e1abf6df76f26c99511d69eedc..00e2bfdf113489f0bbb0c38bba8f25841573e00d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/project/ProjectListDeletionConfirmationDialog.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/project/ProjectListDeletionConfirmationDialog.java @@ -16,6 +16,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.project; +import java.util.Collections; import java.util.List; import ch.systemsx.cisd.openbis.generic.client.web.client.ICommonClientServiceAsync; @@ -43,6 +44,13 @@ public final class ProjectListDeletionConfirmationDialog extends this.callback = callback; } + public ProjectListDeletionConfirmationDialog( + IViewContext<ICommonClientServiceAsync> viewContext, Project project, + AbstractAsyncCallback<Void> callback) + { + this(viewContext, Collections.singletonList(project), callback); + } + @Override protected void executeConfirmedAction() {