SWT Shell inheritance problem

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

SWT Shell inheritance problem

Postby grondeau » Mon Feb 05, 2007 12:13 pm

Shell inheritance works well at runtime but in Eclipe editor I can't see the widgets in the subclass. For example, class A extends Shell and defines Button X, class B extends class A and defines button Y. In Eclipse, when I look at class A I can see the button but when I look at class B, I see nothing. If you execute the application (which instantiates class B), both buttons are visible. Is this supported?
grondeau
 
Posts: 3
Joined: Mon Feb 05, 2007 11:53 am

Re: SWT Shell inheritance problem

Postby Eric Clayberg » Tue Feb 06, 2007 5:04 am

grondeau wrote:Shell inheritance works well at runtime but in Eclipe editor I can't see the widgets in the subclass. For example, class A extends Shell and defines Button X, class B extends class A and defines button Y. In Eclipse, when I look at class A I can see the button but when I look at class B, I see nothing. If you execute the application (which instantiates class B), both buttons are visible. Is this supported?

Yes. See the following example:

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Shell1 extends Shell {
   private Button checkBox;
   private Button helloButton;
   public static void main(String args[]) {
      try {
         Display display = Display.getDefault();
         Shell1 shell = new Shell1(display, SWT.SHELL_TRIM);
         shell.open();
         shell.layout();
         while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
               display.sleep();
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   public Shell1(Display display, int style) {
      super(display, style);
      setText("SWT Application");
      setSize(500, 375);
      helloButton = new Button(this, SWT.NONE);
      helloButton.setText("Hello");
      helloButton.setBounds(14, 13, 131, 62);
      checkBox = new Button(this, SWT.CHECK);
      checkBox.setText("Check Button");
      checkBox.setBounds(151, 27, 186, 35);
   }
   protected void checkSubclass() {
      // Disable the check that prevents subclassing of SWT components
   }
   public Button getHelloButton() {
      return helloButton;
   }
   public String getCheckBoxText() {
      return checkBox.getText();
   }
   public void setCheckBoxText(String text) {
      checkBox.setText(text);
   }
}

Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
public class Shell2 extends Shell1 {
   public static void main(String args[]) {
      try {
         Display display = Display.getDefault();
         Shell2 shell = new Shell2(display, SWT.SHELL_TRIM);
         shell.open();
         shell.layout();
         while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
               display.sleep();
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
   public Shell2(Display display, int style) {
      super(display, style);
      setText("SWT Application");
      setSize(500, 375);
      final Button button = new Button(this, SWT.NONE);
      button.setText("button");
      button.setBounds(147, 90, 107, 47);
      setCheckBoxText("My Label");
      getHelloButton().setText("World");
      getHelloButton().setLocation(10, 82);
   }
}

Image
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby grondeau » Tue Feb 06, 2007 7:09 am

I have taken the sample code in your reply and pasted it in my Eclipse environment. Shell1 class displays exactly like expected. Shell2 class displays an empty grey panel with
Unknown Window Type
on top of the tool bar. Is there a configuration parameter somewhere to enable this feature?
grondeau
 
Posts: 3
Joined: Mon Feb 05, 2007 11:53 am

Postby Eric Clayberg » Tue Feb 06, 2007 8:33 am

1) Make sure that you are using the latest SWT Designer build

2) Make sure that your project is building correctly and that .class files exist in your /bin directory for both classes (consider running the (Project > Clean command).

3) Check your Eclipse .log file for exceptions.

4) If that does not help, try the suggestions listed here.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Postby grondeau » Thu Feb 08, 2007 8:05 am

Thank you for helping me solve this problem. I have verified each suggestions and installed the latest version (6.1). There is an exception reported in Eclipse log. The inherited Shell1 can't be found. This happens when opening the design tab for Shell2. There are no java errors (no red) and if the application is executed it performs as expected, showing the merged widgets from shell1 and 2. I can't figure out how to solve this. Here is the log.
Code: Select all
!ENTRY com.swtdesigner 4 4 2007-02-08 11:32:54.876
!MESSAGE Designer internal error [6.1.0.20070208071007]: Shell1
!STACK 0
java.lang.ClassNotFoundException: Shell1
   at com.swtdesigner.model.util.ast.ASTEditor.loadClass(ASTEditor.java:334)
   at com.swtdesigner.model.parser.factory.JavaInfoFactory.loadComponentClass(JavaInfoFactory.java:622)
   at com.swtdesigner.model.parser.factory.JavaInfoFactory.loadComponentClass(JavaInfoFactory.java:618)
   at com.swtdesigner.model.parser.JavaInfoParser$ParserVisitor.visit(JavaInfoParser.java:2677)
   at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:466)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466)
   at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2536)
   at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:212)
   at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2466)
   at com.swtdesigner.model.parser.JavaInfoParser.parse(JavaInfoParser.java:202)
   at com.swtdesigner.gef.DesignerEditor.parseCompilationUnit(DesignerEditor.java:1064)
   at com.swtdesigner.gef.DesignerEditor$17.execute(DesignerEditor.java:1001)
   at com.swtdesigner.model.swing.properties.custom.DesignTimeHelper.execute(DesignTimeHelper.java:54)
   at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:995)
   at com.swtdesigner.gef.DesignerEditor.handleActivate(DesignerEditor.java:991)
   at com.swtdesigner.editors.MultiPageEditor.showDesignEditor(MultiPageEditor.java:413)
   at com.swtdesigner.editors.MultiPageEditor$2.widgetSelected(MultiPageEditor.java:183)
   at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:90)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:952)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:937)
   at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:709)
   at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3171)
   at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1953)
   at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:288)
   at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
   at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
   at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
   at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
   at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
   at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
   at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
   at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
   at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
   at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
   at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
   at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
   at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
   at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
   at org.eclipse.core.launcher.Main.run(Main.java:977)
   at org.eclipse.core.launcher.Main.main(Main.java:952)
grondeau
 
Posts: 3
Joined: Mon Feb 05, 2007 11:53 am

Postby Eric Clayberg » Thu Feb 08, 2007 8:34 am

grondeau wrote:The inherited Shell1 can't be found. This happens when opening the design tab for Shell2. There are no java errors (no red) and if the application is executed it performs as expected, showing the merged widgets from shell1 and 2. I can't figure out how to solve this.

In general, a ClassNotFoundException implies either a classpath problem or a compilation problem.

Can you confirm that there is a Shell1.class file in your project's /bin directory?

Have you tried the Project > Clean... command?

If that does not help, ZIP up your entire project and end it to us (it only needs to contain the two Shell classes).
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests