关于eclipse rcp中的视图内容刷新,请大神帮忙

maidou2007 发布于 2013/10/15 10:23
阅读 1K+
收藏 0

请问:view中添加的控件是动态变化的,就是通过点击工具栏里的按钮来添加view中的内容,现在的问题是第一次点击按钮添加到view中的内容显示出来了,但第二次点击之后添加的内容在view上闪了一下还是第一次的内容,如果把view最小化,在最大化,第二次的内容又会闪一下,但最终显示的还是第一次的内容,这是怎么回事啊,求大神帮忙。下面是代码:
view的public void createPartControl(Composite parent){ 
 composite = new Composite(parent, SWT.EMBEDDED);
 RGB rgb = new RGB(255,255,255);
 org.eclipse.swt.graphics.Color color = new      org.eclipse.swt.graphics.Color(getSite().getShell().getDisplay(),rgb);
 composite.setBackground(color);
 FillLayout layout = new FillLayout();
 layout.marginHeight = 0;
 layout.marginWidth = 0;
 composite.setLayout(layout);
}

 private class ShowAction  extends Action {
   ......
    }
    public void run(){
                 .........
         IViewReference[] vfs  = getSite().getWorkbenchWindow().getActivePage().getViewReferences();
  IViewPart vw;
         for(int i=0;i<vfs.length;i++){
  vw = vfs[i].getView(false);
  if(vw.getTitle().equals("数据展示")){
                   final JComponent treeview = demo(filePath, label);
     Composite com = ((View)vw).composite;
            final Frame frame = SWT_AWT.new_Frame(com);
     frame.add(treeview);
     frame.pack();
                   frame.setVisible(true);   
  }
  }
 }
 public static JComponent demo(String datafile, final String label) {
        Color BACKGROUND = Color.WHITE;
        Color FOREGROUND = Color.BLACK;
       
        Tree t = null;
        try {
            t = (Tree)new TreeMLReader().readGraph(datafile);
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(1);
        }
       
        // create a new treemap
        final TreeView tview = new TreeView(t, label);
        Table table = t.getNodeTable();
        tview.setBackground(BACKGROUND);
        tview.setForeground(FOREGROUND);
       
        // create a search panel for the tree map
        JSearchPanel search = new JSearchPanel(tview.getVisualization(),
            treeNodes, Visualization.SEARCH_ITEMS, label, true, true);
        search.setShowResultCount(true);
        search.setBorder(BorderFactory.createEmptyBorder(5,5,4,0));
        search.setFont(FontLib.getFont("微软雅黑", Font.PLAIN, 11));
        search.setBackground(BACKGROUND);
        search.setForeground(FOREGROUND);
       
        final JFastLabel title = new JFastLabel("  My TEST      ");
        title.setPreferredSize(new Dimension(350, 20));
        title.setVerticalAlignment(SwingConstants.BOTTOM);
        title.setBorder(BorderFactory.createEmptyBorder(3,0,0,0));
        title.setFont(FontLib.getFont("微软雅黑", Font.PLAIN, 16));   //Tahoma
        title.setBackground(BACKGROUND);
        title.setForeground(FOREGROUND);
       
        tview.addControlListener(new ControlAdapter() {
            public void itemEntered(VisualItem item, MouseEvent e) {
                if ( item.canGetString(label) )
                    title.setText(item.getString(label));
            }
            public void itemExited(VisualItem item, MouseEvent e) {
                title.setText(null);
            }
        });
       
        Box box = new Box(BoxLayout.X_AXIS);
        box.add(Box.createHorizontalStrut(10));
        box.add(title);
        box.add(Box.createHorizontalGlue());
        box.add(search);
        box.add(Box.createHorizontalStrut(3));
        box.setBackground(BACKGROUND);
       
        JPanel panel = new JPanel(new BorderLayout());
        panel.setBackground(BACKGROUND);
        panel.setForeground(FOREGROUND);
        panel.add(tview, BorderLayout.CENTER);
        panel.add(box, BorderLayout.SOUTH);

        panel.invalidate();
        panel.updateUI();
        panel.setVisible(true);
        return panel;
    }

加载中
0
m
maidou2007
大家帮帮忙啊,困扰我好多天
0
m
maidou2007

谁能解决请吃饭

0
张文瑞

 Composite com = ((View)vw).composite; 楼主这句能获取到composite吗?

0
空指针
空指针

兄弟啊,为题解决了吗 ? 我也遇到同样的问题


返回顶部
顶部