How to hide a workflow button in workflow bar

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to hide a workflow button in workflow bar

sammy
I want to hide my workflow button in the following cases -

1. document is created and not locally published
2. a previous version of the document is live

I did the following -

My plugin class implements CompatibilityWorkflowPlugin and I have my onModelChanged method overridden

public class MobexPublishActionsWorkflowPlugin extends CompatibilityWorkflowPlugin<MobexPublishActionsWorkflow> {

    private WorkflowAction mobexPublishAction;
    private WorkflowAction mobexUnpublishAction;

    public MobexPublishActionsWorkflowPlugin(IPluginContext context, IPluginConfig config) throws RemoteException, RepositoryException {
        super(context, config);

        mobexPublishAction = new WorkflowAction("publishtomobex", "Publish to Mobex", null) {

            @Override
            protected ResourceReference getIcon() {
                return new ResourceReference(getClass(), "m.png");
            }

            @Override
            protected String execute(MobexPublishActionsWorkflow workflow) {
                try {
                    workflow.publishToMobex();
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                    return e.getMessage();
                }
            }
        };

        mobexUnpublishAction = new WorkflowAction("takeoffline", "Unpublish from Mobex", null) {

            @Override
            protected ResourceReference getIcon() {
                return new ResourceReference(getClass(), "m.png");
            }

            @Override
            protected String execute(MobexPublishActionsWorkflow workflow) {
                try {
                    workflow.takeOffline();
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                    return e.getMessage();
                }
            }
        };
       
        add(mobexPublishAction);
        add(mobexUnpublishAction);
       

     
    }

    @Override
    protected void onModelChanged() {
        super.onModelChanged();
        try {
        System.out.println("on model changed called !");
            WorkflowManager manager = ((UserSession) org.apache.wicket.Session.get()).getWorkflowManager();
            WorkflowDescriptor workflowDescriptor = (WorkflowDescriptor) getDefaultModelObject();
            if (workflowDescriptor != null) {
                Workflow workflow = manager.getWorkflow(workflowDescriptor);
                Map<String, Serializable> info = workflow.hints();

                System.out.println("hints:"+info);
                Logger.getLogger(this.getClass()).info("hints:"+info);
                 
                if (info.containsKey("depublish") && info.get("depublish") instanceof Boolean && ((Boolean) info.get("depublish")).booleanValue()) {
               
                mobexPublishAction.setVisible(true);
                    mobexUnpublishAction.setVisible(true);
                }
                else
                {
               
                mobexPublishAction.setVisible(false);
                    mobexUnpublishAction.setVisible(false);
                }
         

            }
        } catch (RepositoryException ex) {
            ex.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (WorkflowException e) {
            e.printStackTrace();
        }
    }
}

This code hides the my button in the case 1 but not 2.
When I open a document of which a previous is live, onModelChanged method is not called.

Is there another way to fix it ?


Sameera Thangudu
130 W 42nd Street | New York, NY 10036
sthangudu@northps.com | www.northps.com | WE LEAD WITH EXPERIENCE.
Reply | Threaded
Open this post in threaded view
|

Re: How to hide a workflow button in workflow bar

Frank van Lankvelt
you should realize that the workflow plugin is instantiated for each
variant of the document.
So the hints() method in your workflow should return false for all
actions for all variants in the appropriate cases.  (I don't know what
'locally published' means)

cheers, Frank

On Tue, Mar 19, 2013 at 4:04 PM, sammy <[hidden email]> wrote:

> I want to hide my workflow button in the following cases -
>
> 1. document is created and not locally published
> 2. a previous version of the document is live
>
> I did the following -
>
> My plugin class implements CompatibilityWorkflowPlugin and I have my
> onModelChanged method overridden
>
> public class MobexPublishActionsWorkflowPlugin extends
> CompatibilityWorkflowPlugin<MobexPublishActionsWorkflow> {
>
>     private WorkflowAction mobexPublishAction;
>     private WorkflowAction mobexUnpublishAction;
>
>     public MobexPublishActionsWorkflowPlugin(IPluginContext context,
> IPluginConfig config) throws RemoteException, RepositoryException {
>         super(context, config);
>
>         mobexPublishAction = new WorkflowAction("publishtomobex", "Publish
> to Mobex", null) {
>
>             @Override
>             protected ResourceReference getIcon() {
>                 return new ResourceReference(getClass(), "m.png");
>             }
>
>             @Override
>             protected String execute(MobexPublishActionsWorkflow workflow) {
>                 try {
>                     workflow.publishToMobex();
>                     return null;
>                 } catch (Exception e) {
>                     e.printStackTrace();
>                     return e.getMessage();
>                 }
>             }
>         };
>
>         mobexUnpublishAction = new WorkflowAction("takeoffline", "Unpublish
> from Mobex", null) {
>
>             @Override
>             protected ResourceReference getIcon() {
>                 return new ResourceReference(getClass(), "m.png");
>             }
>
>             @Override
>             protected String execute(MobexPublishActionsWorkflow workflow) {
>                 try {
>                     workflow.takeOffline();
>                     return null;
>                 } catch (Exception e) {
>                     e.printStackTrace();
>                     return e.getMessage();
>                 }
>             }
>         };
>
>         add(mobexPublishAction);
>         add(mobexUnpublishAction);
>
>
>
>     }
>
>     @Override
>     protected void onModelChanged() {
>         super.onModelChanged();
>         try {
>                 System.out.println("on model changed called !");
>             WorkflowManager manager = ((UserSession)
> org.apache.wicket.Session.get()).getWorkflowManager();
>             WorkflowDescriptor workflowDescriptor = (WorkflowDescriptor)
> getDefaultModelObject();
>             if (workflowDescriptor != null) {
>                 Workflow workflow = manager.getWorkflow(workflowDescriptor);
>                 Map<String, Serializable> info = workflow.hints();
>
>                 System.out.println("hints:"+info);
>                 Logger.getLogger(this.getClass()).info("hints:"+info);
>
>                 if (info.containsKey("depublish") && info.get("depublish")
> instanceof Boolean && ((Boolean) info.get("depublish")).booleanValue()) {
>
>                         mobexPublishAction.setVisible(true);
>                     mobexUnpublishAction.setVisible(true);
>                 }
>                 else
>                 {
>
>                         mobexPublishAction.setVisible(false);
>                     mobexUnpublishAction.setVisible(false);
>                 }
>
>
>             }
>         } catch (RepositoryException ex) {
>             ex.printStackTrace();
>         } catch (RemoteException e) {
>             e.printStackTrace();
>         } catch (WorkflowException e) {
>             e.printStackTrace();
>         }
>     }
> }
>
> This code hides the my button in the case 1 but not 2.
> When I open a document of which a previous is live, onModelChanged method is
> not called.
>
> Is there another way to fix it ?
>
>
>
>
>
>
> -----
> Sameera Thangudu
> 130 W 42nd Street | New York, NY 10036
> [hidden email] | www.northps.com | WE LEAD WITH EXPERIENCE.
> --
> View this message in context: http://hippo.2275632.n2.nabble.com/How-to-hide-a-workflow-button-in-workflow-bar-tp7580684.html
> Sent from the Hippo CMS 7 mailing list archive at Nabble.com.
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: How to hide a workflow button in workflow bar

sammy
I meant publish action under Publication workflow button.

When the document property hippostd:stateSummary is changed, onModelChanged method is not called. So my button visibility is not set.

Please advise how to hide the button in this case.
Sameera Thangudu
130 W 42nd Street | New York, NY 10036
sthangudu@northps.com | www.northps.com | WE LEAD WITH EXPERIENCE.