java更新后SWT Composite没有显示

时间:2016-07-25 13:21:40

标签: java eclipse swt

我们最近将Eclipse从Helios升级到Kepler,将JDK从7升级到8.应用程序的顶部和底部都有横幅,但自更新以来它们不再显示。我没有在这段代码上工作,这是我第一次看到它,所以我不熟悉它。 topBanner,bottomBanner和相应的标签出现了。某些方法显示为已弃用

IWorkbenchWindowConfigurer.createMenuBar //replaced with new Menu(shell)
IWorkbenchWindowConfigurer.createCoolBarControl // replaced with new CoolBar(shell, someColor);
IWorkbenchWindowConfigurer.createPageComposite // don't know what to replace it with

进行这些更新并未对应用程序进行任何可见的更改。这是我的应用程序代码:

private static Composite topBanner,bottomBanner;
private Control toolbar;
private Control page;
private static Label topLabel,bottomLabel;
private int labelBackgroundColor=SWT.COLOR_YELLOW;

public static void setClassificationLabelColor(Color barColor)
{
    int fontColor = SWT.COLOR_WHITE;
    if (barColor.getGreen() == 255) {
        fontColor = SWT.COLOR_BLACK;
    }
    topBanner.setBackground(barColor);
    topLabel.setBackground(barColor);
    topLabel.setForeground(Display.getDefault().getSystemColor(fontColor));
    bottomBanner.setBackground(barColor);
    bottomLabel.setBackground(barColor);
    bottomLabel.setForeground(Display.getDefault().getSystemColor(fontColor));
    topBanner.layout();
    bottomBanner.layout();
}

public static void setClassificationLabelText(String text)
{
    if (text == null) { text = ""; }
    topLabel.setText(text);
    bottomLabel.setText(text);
    topBanner.layout();
    bottomBanner.layout();
}

public void createWindowContents(Shell shell)
{
    GridLayout gl;
    GridData gd;
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
    shell.setLayout(new GridLayout(1, false));
    String defaultBanner = String.valueOf(SystemDAO.getDefaultBannerClassification(SystemDAO.MAIN_ROW_ID));

    //top banner
    topBanner = new Composite(configurer.getWindow().getShell(), 0);
    topBanner.setBackground(Display.getDefault().getSystemColor(labelBackgroundColor));
    gd=new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint=12;
    topBanner.setLayoutData(gd);
    gl=new GridLayout();gl.marginTop=-6;
    topBanner.setLayout(gl);

    //top label
    topLabel=new Label(topBanner,SWT.None);
    topLabel.setBackground(Display.getDefault().getSystemColor(labelBackgroundColor));
    topLabel.setText(defaultBanner);
    topLabel.setLayoutData(new GridData(SWT.CENTER,SWT.BOTTOM,true,false));

    //menu
    org.eclipse.swt.widgets.Menu menu = configurer.createMenuBar(); //deprecated**
    shell.setMenuBar(menu);

    //tool bar
    toolbar = configurer.createCoolBarControl(shell); //deprecated**
    ((CoolBar)toolbar).setLocked(true);
    toolbar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    //page
    page = configurer.createPageComposite(shell); //deprecated**
    page.setLayoutData(new GridData(GridData.FILL_BOTH));

    //bottom banner
    bottomBanner = new Composite(configurer.getWindow().getShell(), 0);        
    bottomBanner.setBackground(Display.getDefault().getSystemColor(labelBackgroundColor));        
    gd=new GridData(GridData.FILL_HORIZONTAL);
    gd.heightHint=12;
    bottomBanner.setLayoutData(gd);
    gl=new GridLayout();gl.marginTop=-6;
    bottomBanner.setLayout(gl);

    //bottom label
    bottomLabel=new Label(bottomBanner,SWT.None);
    bottomLabel.setBackground(Display.getDefault().getSystemColor(labelBackgroundColor));
    bottomLabel.setText(defaultBanner);
    bottomLabel.setLayoutData(new GridData(SWT.CENTER,SWT.BOTTOM,true,false));

    //status bar
    Control statusLine=configurer.createStatusLineControl(configurer.getWindow().getShell());
    gd=new GridData(GridData.FILL_HORIZONTAL);
    statusLine.setLayoutData(gd);

    createProgressIndicator((Composite)statusLine);
}

private void createProgressIndicator(Composite parent) {
    if (getWindowConfigurer().getShowProgressIndicator()) {
        WorkbenchWindow window = (WorkbenchWindow) getWindowConfigurer().getWindow();
        progressRegion = new ProgressRegion();
        progressRegion.createContents(parent, window);
    }
}
@Override
public void postWindowCreate() {
    /* removes unwanted IDE contribution items from the toolbar */
    IActionBarConfigurer actionBarConfigurer = getWindowConfigurer().getActionBarConfigurer();
    IContributionItem[] coolItems = actionBarConfigurer.getCoolBarManager().getItems();

    for (int i=0; i < coolItems.length; i++) {
        if (coolItems[i] instanceof ToolBarContributionItem) {
            ToolBarContributionItem toolbarItem = (ToolBarContributionItem) coolItems[i];
            if (toolbarItem.getId().equals("org.eclipse.ui.WorkingSetActionSet") || //$NON-NLS-1$
                    toolbarItem.getId().equals("org.eclipse.ui.edit.text.actionSet.annotationNavigation") || //$NON-NLS-1$
                    toolbarItem.getId().equals("org.eclipse.ui.edit.text.actionSet.navigation")||
                    toolbarItem.getId().equals("org.eclipse.debug.ui.launchActionSet")||
                    toolbarItem.getId().equals("org.eclipse.search.searchActionSet")) { //$NON-NLS-1$
                toolbarItem.getToolBarManager().removeAll();
            }
        }
    }

    actionBarConfigurer.getCoolBarManager().update(true);

    //have the application window initially maximized
    getWindowConfigurer().getWindow().getShell().setMaximized(true);
}

我一直试图解决这个问题两天,但我对SWT并不是很熟悉。任何帮助表示赞赏。

0 个答案:

没有答案