X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2FCmsView.java;h=ce0acb89fd2b68c0c2c249b6f9df362310d0483c;hb=1233dcea2383bfe5c83e5ec33d0c502afff22601;hp=6d70935d7e4a0ffd9d8205cac0404dc97fdbf2ff;hpb=28eae1d74809cb8752ab72219063e822e264c77d;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java index 6d70935d7..ce0acb89f 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java @@ -2,9 +2,12 @@ package org.argeo.cms.ui; import javax.security.auth.login.LoginContext; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; + /** Provides interaction with the CMS system. */ public interface CmsView { - String KEY = "org.argeo.cms.ui.view"; + //String KEY = "org.argeo.cms.ui.view"; UxContext getUxContext(); @@ -24,4 +27,27 @@ public interface CmsView { CmsImageManager getImageManager(); boolean isAnonymous(); + + static CmsView getCmsView(Composite parent) { + // find parent shell + Shell topShell = parent.getShell(); + while (topShell.getParent() != null) + topShell = (Shell) topShell.getParent(); + return (CmsView) topShell.getData(CmsView.class.getName()); + } + + static void registerCmsView(Shell shell, CmsView view) { + // find parent shell + Shell topShell = shell; + while (topShell.getParent() != null) + topShell = (Shell) topShell.getParent(); + // check if already set + if (topShell.getData(CmsView.class.getName()) != null) { + CmsView registeredView = (CmsView) topShell.getData(CmsView.class.getName()); + throw new IllegalArgumentException( + "Cms view " + registeredView + " already registered in this shell"); + } + shell.setData(CmsView.class.getName(), view); + } + }