Tuesday, January 14, 2014

How to implement client plugins?


Hi,

in what follows, I assume a basic understanding of Eclipse plugins and extension points, as described on

   http://wiki.eclipse.org/FAQ_What_are_extensions_and_extension_points%3F

I am currently building a UI, which will hopefully run on several customers sites. Naturally, the customers will ask for custom modifications, and the like, and I am currently thinking of the best way to achieve that.

Basically, my UI will be about the representation of database objects. The server side will allow customization of these objects, for example it will be possible to add custom attributes.

So, in an ideal world, I'd have my client code look something like this:

        public interface IDetailsPage {
            Widget createDetailsFor(DatabaseObject pObject);
        }
        // Show details for the given database object.
    public class DetailsViewer {
       private final DatabaseObject object;
       private final DefaultDetailsPage defaultPage = new DefaultDetailsPage();
 
       public DetailsViewer(pObject) {
         object = pObject;
       }
       public Widget createDetails() {
         ExtensionPoint<DetailsPage> ep = ExtensionPointRegistry.getExtensionPoint("DetailsPage");
         final List<DetailsPage> extensions = ep.getExtensions();
         for (DetailsPage dp : extensions) {
           final Widget w = dp.createDetailsFor(object);
           if (w != null) {
             return w;
           }
           return defaultPage.createDetailsFor(object);
       }
    }

And a typical plugin implementations could look like this:

  public class FooDetailsPage extends DefaultDetailsPage {
    public Widget createDetailsFor(DatabaseObject pObject) {
      final Widget w = super.createDetailsFor(pObject);
      if ("Foo".equals(pObject.getType())) {
        final ScrollPanel sp = new ScrollPanel();
        sp.add(w);  // Add the default contents.
        ...         // Add more contents.
        return sp;
      }
      return w;
    }
  }

Unfortunately, we can hardly create such mechanism, because we do not have dynamic binding...


Questions:

  1. Any ideas, how I might achieve a similar solution?
  2. My impression is, that we could at least have something like GWT.create(String), by doing the following:
    • Have the GWT compiler create a list of classes and generate the method roughly like thi

    public static void create(String pClassName) {
      if ("Class1".equals(pClassName)) {
        return new Class1();
      } else if ("Class2".equals(pClassName)) {
        return new Class2();
      }
      ...
      } else {
        throw new ClassNotFoundException("Class " + pClassName + " is unknown, or doesn't have a public"
                                         + " default constructor.");
            }
       }

If we had that, we could indeed implement the ExtensionPoint stuff. (Have configuration on the server side, for example via plugin.xml resources, and copy the configuration to the client upon start.)

Jochen


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment