Designer has lost ability to graphically edit Jface Window

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

Designer has lost ability to graphically edit Jface Window

Postby rgallen » Sat Nov 01, 2003 9:03 pm

This is code I worked on a couple of weeks ago, and I have since installed 1.2.1 (and subsequently uninstalled it), so I'm not sure when this ceased to work, but it appears that designer can no longer parse the code and edit the controls in the design pane. Now I am a complete newbie so I may have done something incredibly silly, but my understanding is that Designer should be able to parse out what it can deal with, and continue to allow graphical editting of these components in the presence of user modifications to the source.... no ?

Here is the body of code that causes the problem for me. I am using Eclipse 3.0M3, and SWT Designer 1.2.0.

Code: Select all
public class JfaceApp extends ApplicationWindow {

   public class ExitAction extends Action
   {
     ApplicationWindow window;

     public ExitAction(ApplicationWindow w)
     {
      window = w;
      setText("E&xit@Ctrl+W");
      setToolTipText("Exit the application");      
     }

     public void run()
     {
      window.close();
     }
   }

   public class OpenAction extends Action
   {
     JfaceApp window;

     public OpenAction(JfaceApp w)
     {
      window = w;
      setText("Run");
      setToolTipText("Run the associated program on a file");
      setImageDescriptor(
        ImageDescriptor.createFromURL(Util.newURL("file:icons/run.gif")));
     }

     public void run()
     {
      IStructuredSelection selection = window.getTableSelection();
      if (selection.size() != 1)
        return;

      File selected_file = (File) selection.getFirstElement();
      if (selected_file.isFile())
      {
        Program.launch(selected_file.getAbsolutePath());
      }
     }
   }
      
   public class CopyFileNamesToClipboardAction extends Action
   {
     JfaceApp window;

     public CopyFileNamesToClipboardAction(JfaceApp w)
     {
      window = w;
      setToolTipText("Copy absolute file names of selected files to the clipboard");
      setText("Copy File &Names@Ctrl+Shift+C");
     }


     public void run()
     {
      Clipboard clipboard = Util.getClipboard();
      TextTransfer text_transfer = TextTransfer.getInstance();
   
      IStructuredSelection selection = window.getTableSelection();
      if (selection.isEmpty())
      {
        return;
      }

      StringBuffer string_buffer = new StringBuffer();
      for (Iterator i = selection.iterator(); i.hasNext();)
      {
        File file = (File) i.next();
        string_buffer.append(" ");
        string_buffer.append(file.getAbsolutePath());
      }

      clipboard.setContents(
        new Object[] { string_buffer.toString()},
        new Transfer[] { text_transfer });
     }
   }
   
   public class FileSorter extends ViewerSorter
   {
     public int category(Object element)
     {
      return ((File) element).isDirectory() ? 0 : 1;
     }
   }

   public class AllowOnlyFoldersFilter extends ViewerFilter
   {
     public boolean select(Viewer viewer, Object parent, Object element)
     {
      return ((File) element).isDirectory();
     }
   }

   class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
      public String getColumnText(Object element, int columnIndex) {
         switch(columnIndex) {
            case 0:
               return ((File) element).getName();
            case 1:
               if(((File) element).isDirectory()) {
                  return "File folder";
               } else {
                  return  String.valueOf(((File) element).length());
               }
            default:
               return "";
         }
      }
      public Image getColumnImage(Object element, int columnIndex) {
         if (columnIndex != 0)
         {
           return null;
         }

         if (((File) element).isDirectory())
         {
           return Util.getImageRegistry().get("folder");
         }
         else
         {
           return Util.getImageRegistry().get("file");
         }
      }
   }
   private TableViewer tableViewer;
   private TreeViewer treeViewer;

   class TreeLabelProvider extends LabelProvider {
      public String getText(Object element) {
         return ((File) element).getName();
      }
      public Image getImage(Object element) {
         if (((File) element).isDirectory())
         {
           return Util.getImageRegistry().get("folder");
         }
         else
         {
           return Util.getImageRegistry().get("file");
         }
      }
   }
   class ContentProvider implements IStructuredContentProvider {
      public Object[] getElements(Object inputElement) {
         Object[] kids = null;
         kids = ((File) inputElement).listFiles();
         return kids == null ? new Object[0] : kids;
      }
      public void dispose() {
      }
      public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
      }
   }
   class TreeContentProvider implements IStructuredContentProvider, ITreeContentProvider {
      public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
      }
      public void dispose() {
      }
      public Object[] getElements(Object inputElement) {
         return getChildren(inputElement);
      }
      public Object[] getChildren(Object parentElement) {
         Object[] kids = ((File) parentElement).listFiles();
         return kids == null ? new Object[0] : kids;
      }
      public Object getParent(Object element) {
         return ((File)element).getParent();
      }
      public boolean hasChildren(Object element) {
         return getChildren(element).length > 0;
      }
   }
   public JfaceApp() {
      super(null);
      createActions();
      addToolBar(SWT.NONE);
      addMenuBar();
   }
   protected Control createContents(Composite parent) {
      Composite composite = new Composite(parent, SWT.NONE);
      final GridLayout gridLayout = new GridLayout();
      gridLayout.numColumns = 2;
      composite.setLayout(gridLayout);
      {
         treeViewer = new TreeViewer(composite, SWT.BORDER);
         treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent e) {
               IStructuredSelection selection =
                 (IStructuredSelection) e.getSelection();

               Object selected_file = selection.getFirstElement();
               tableViewer.setInput(selected_file);   
            }
         });
         treeViewer.setLabelProvider(new TreeLabelProvider());
         treeViewer.setContentProvider(new TreeContentProvider());
         final Tree tree = treeViewer.getTree();
         tree.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL));
         treeViewer.setInput(new File("c:\\"));
         treeViewer.addFilter(new AllowOnlyFoldersFilter());
         
      }
      {
         tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
         tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent e) {
               IStructuredSelection selection =
                 (IStructuredSelection) e.getSelection();
               setStatus("Number of items selected is " + selection.size());                           
            }
         });
         tableViewer.setLabelProvider(new TableLabelProvider());
         tableViewer.setContentProvider(new ContentProvider());
         final Table table = tableViewer.getTable();
         table.setHeaderVisible(true);
         table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
         {
            final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
            tableColumn.setWidth(100);
            tableColumn.setText("Name");
         }
         {
            final TableColumn tableColumn = new TableColumn(table, SWT.NONE);
            tableColumn.setWidth(100);
            tableColumn.setText("Size");
         }
         tableViewer.setInput(new File("c:\\"));
         tableViewer.setSorter(new FileSorter());
         
      }
      // DESIGNER: Add controls before this line.
      return composite;
   }
   private void createActions() {
   }
   protected MenuManager createMenuManager() {
      MenuManager result=new MenuManager("menu");

      MenuManager file_menu=new MenuManager("&File");
      MenuManager edit_menu=new MenuManager("&Edit");
      MenuManager view_menu=new MenuManager("&View");

      result.add(file_menu);
      result.add(edit_menu);
      result.add(view_menu);

      file_menu.add(new ExitAction(this));
      edit_menu.add(new CopyFileNamesToClipboardAction(this));
      edit_menu.add(new OpenAction(this));
            
      // DESIGNER: Add controls before this line.
      return result;
   }
   protected ToolBarManager createToolBarManager(int arg0) {
      ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT | SWT.WRAP);
      // DESIGNER: Add controls before this line.
      return toolBarManager;
   }
   
   public IStructuredSelection getTableSelection()
   {
     return (IStructuredSelection) (tableViewer.getSelection());
   }
   
   public void run() {
      open();
      Display display = Display.getCurrent();
      Shell shell = getShell();
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
      }
   }
   public static void main(String args[]) {
      Display display = new Display();
      JfaceApp window = new JfaceApp();
      window.addStatusLine();
      window.run();
      Util.getClipboard().dispose();
   }
   protected void configureShell(Shell newShell) {
      super.configureShell(newShell);
      newShell.setText("Explorer");
   }
}
rgallen
 
Posts: 15
Joined: Sun Oct 12, 2003 7:45 pm

Return to SWT Designer

Who is online

Users browsing this forum: Google [Bot] and 1 guest