当前位置:编程学习 > JAVA >>

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

请问: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;
    } eclipse rcp --------------------编程问答-------------------- 自己先顶一下 --------------------编程问答-------------------- 代码没具体看, 但在此点击工具条应该判断一下view是否已经存在,存在就刷新一下,不存在就创建,应该就会解决这个问题。
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,