From 2b86d097148a80a388e055b63addcc79a62d3f8f Mon Sep 17 00:00:00 2001 From: rkv Date: Thu, 18 Apr 2013 13:09:52 +0000 Subject: [PATCH] Fix of document popup menu refreshing after document import, delete and version. Remove version is fixed: version counter is decremented now in the previous version. Document rights canRemove takes into account not only published documents. --- .../splat/service/PublicationServiceImpl.java | 4 +-- .../org/splat/service/StepServiceImpl.java | 1 + .../src/org/splat/som/DocumentRights.java | 3 +- .../splat/simer/BaseUploadDocumentAction.java | 22 +++++++++---- .../org/splat/simer/EditDocumentAction.java | 33 ++++++++++--------- .../org/splat/simer/ImportDocumentAction.java | 5 +-- .../splat/simer/VersionDocumentAction.java | 24 +++++++------- 7 files changed, 50 insertions(+), 42 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java index a901160..dd01f84 100644 --- a/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/PublicationServiceImpl.java @@ -304,9 +304,7 @@ public class PublicationServiceImpl implements PublicationService { compatible.add(docusedby[i]); } } - List relist = current.getRelations(UsedByRelation.class); - for (Iterator i = relist.iterator(); i.hasNext();) { - Publication using = i.next(); + for (Publication using : current.getRelations(UsedByRelation.class)) { if (!compatible.contains(using.getIndex())) { outdate(using); } diff --git a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java index 6e8e04a..29d53c0 100644 --- a/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/StepServiceImpl.java @@ -501,6 +501,7 @@ public class StepServiceImpl implements StepService { // Republish the previous version if any to avoid it becoming an orphan Document prevVersion = torem.value().getPreviousVersion(); if (prevVersion != null) { + prevVersion.setHistory(prevVersion.getHistory() - 1); add(aStep, new Publication(prevVersion, aStep.getOwner())); getProjectElementDAO().merge(aStep.getOwner()); } diff --git a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java index 571b419..ab19e9c 100644 --- a/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java +++ b/Workspace/Siman-Common/src/org/splat/som/DocumentRights.java @@ -300,7 +300,8 @@ public class DocumentRights { return false; } - List using = _operand.getRelations(UsedByRelation.class); + List using = _operand.value().getRelations( + UsedByRelation.class); return using.isEmpty(); } diff --git a/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java b/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java index c54d950..008b790 100644 --- a/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java @@ -250,7 +250,7 @@ public class BaseUploadDocumentAction extends AbstractUploadNextAction { // ============================================================================================================================== // Getters and setters // ============================================================================================================================== - + public DocumentType getDefaultDocumentType() { return _deftype; } @@ -287,13 +287,13 @@ public class BaseUploadDocumentAction extends AbstractUploadNextAction { this._state = ProgressState.valueOf(state); } - // ============================================================================================================================== + // ========================================================================= // Protected services - // ============================================================================================================================== - + // ========================================================================= + protected void setupDefaultUses(final DocumentType type) { Set uses = type.getDefaultUses(); - + for (Iterator i = uses.iterator(); i.hasNext();) { DocumentType usetype = i.next(); List usedoc = _mystudy.collectInvolvedDocuments(usetype); @@ -308,7 +308,7 @@ public class BaseUploadDocumentAction extends AbstractUploadNextAction { public void setUses(final String list) { this._docuses = list; } - + public String getWriteAccess() { Boolean res = (_mystudy != null); if (res) { @@ -316,4 +316,14 @@ public class BaseUploadDocumentAction extends AbstractUploadNextAction { } return res.toString(); } + + /** + * Refresh the study representation according to the current database content. + */ + public void refreshStudy() { + // Update of the open study + String selection = _mystudy.getSelection(); + _mystudy = open(getStudyService().selectStudy(_mystudy.getIndex())); // Updates the study + _mystudy.setSelection(selection); // Rebuilds the presentation + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java index 6668976..ab8b2fb 100644 --- a/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditDocumentAction.java @@ -53,12 +53,15 @@ public class EditDocumentAction extends DisplayStudyStepAction { * Operations enumeration. */ private enum Execute { + /** + * Possible document operations. + */ renameDocument, accept, promote, demote, review, invalidate, approve, disapprove }; - // ============================================================================================================================== + // ========================================================================= // Action methods - // ============================================================================================================================== + // ========================================================================= /** * Open a study. @@ -111,7 +114,8 @@ public class EditDocumentAction extends DisplayStudyStepAction { getPublicationService().approve(doc, Calendar.getInstance().getTime()); _openStudy.update(doc); - _openStudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state + // Update the menu icon, in case of other documents in approved state + _openStudy.getMenu().refreshSelectedItem(); } res = SUCCESS; } catch (RuntimeException saverror) { @@ -175,10 +179,10 @@ public class EditDocumentAction extends DisplayStudyStepAction { Step step = _openStudy.getSelectedStep(); Publication edited = step.getDocument(Long.valueOf(_index)); Date modifTime = Calendar.getInstance().getTime(); - + // Replace the document source file getPublicationService().replace(edited, upfile, modifTime); - + _openStudy.update(edited); res = SUCCESS; } catch (Exception error) { @@ -202,25 +206,22 @@ public class EditDocumentAction extends DisplayStudyStepAction { setMenu(); _openStudy = getOpenStudy(); Step step = _openStudy.getSelectedStep(); - Publication doctag = step.getDocument(Long.valueOf(_index)); - Long prevVersion = 0L; - if (doctag.value().getPreviousVersion() != null) { - prevVersion = doctag.value().getPreviousVersion().getIndex(); - } if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure - _openStudy.remove(doctag); // Updates the presentation - // The previous version must be republished if any - if (prevVersion > 0) { - _openStudy.add(step.getDocument(prevVersion)); + // Re-opening (refreshing) the currently open study + if (_selection == null) { // Opening a study just newed + _selection = _openStudy.getSelection(); // Default selection } + _openStudy = open(getStudyService().selectStudy( + _openStudy.getIndex())); // Closes the previously open study + _openStudy.setSelection(_selection); } return SUCCESS; } - // ============================================================================================================================== + // ========================================================================= // Getters and setters - // ============================================================================================================================== + // ========================================================================= /** * Set the document title. diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index 748a0f7..70b7623 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -269,10 +269,7 @@ public class ImportDocumentAction extends BaseUploadDocumentAction { _mystudy.add(addoc); // Updates the presentation } else { // Re-opening (refreshing) the currently open study - String selection = _mystudy.getSelection(); - _mystudy = open(getStudyService().selectStudy( - _mystudy.getIndex())); // Updates the study - _mystudy.setSelection(selection); + refreshStudy(); } res = SUCCESS; } catch (FileNotFoundException error) { diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index 90fe6d9..5c41b26 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -79,7 +79,7 @@ public class VersionDocumentAction extends BaseUploadDocumentAction { setupDefaultUses(_deftype); } // Add additional documents used by the current version - for (Relation usesRel: doc.getRelations(UsesRelation.class)) { + for (Relation usesRel : doc.getRelations(UsesRelation.class)) { Document used = (Document) usesRel.getTo(); if (!_defuses.contains(used)) { _defuses.add(used); @@ -93,19 +93,20 @@ public class VersionDocumentAction extends BaseUploadDocumentAction { _usedby.addAll(tag.getRelations(UsedByRelation.class)); // Initialize applicable states list - if(tag.value().getProgressState() == ProgressState.EXTERN) { + if (tag.value().getProgressState() == ProgressState.EXTERN) { _documentStates.add(ProgressState.EXTERN); } else { - _documentStates.add(ProgressState.inWORK); - if (_deftype != null) { - // Check if the validation cycle of the document type can has a review state - ValidationCycle cycle = getStudyService().getValidationCycleOf( - _mystudy.getMystudy(), _deftype); - if ((cycle != null) && cycle.enables(ValidationStep.REVIEW)) { - _documentStates.add(ProgressState.inDRAFT); + _documentStates.add(ProgressState.inWORK); + if (_deftype != null) { + // Check if the validation cycle of the document type can has a review state + ValidationCycle cycle = getStudyService() + .getValidationCycleOf(_mystudy.getMystudy(), + _deftype); + if ((cycle != null) && cycle.enables(ValidationStep.REVIEW)) { + _documentStates.add(ProgressState.inDRAFT); + } } } - } } else { if (!(Constants.NONE.equals(getToolProperty()))) { initializationFullScreenContext(Constants.STUDY_MENU, @@ -203,8 +204,7 @@ public class VersionDocumentAction extends BaseUploadDocumentAction { _state, aDate, listDocuses, _docusedby); // Update of the open study - _mystudy.setSelection(_mystudy.getSelection()); // Rebuilds the presentation - // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document) + refreshStudy(); res = SUCCESS; } catch (FileNotFoundException error) { -- 2.39.2