【问题标题】:How to fix position of layout in a view in eclipse如何在eclipse中的视图中修复布局位置
【发布时间】:2013-01-03 20:03:52
【问题描述】:

我在 Git repo 页面中添加了一个过滤器并修改了 RepositoryView 类。我刚刚提到了这一点,以便您可以在需要时在线找到此代码。我的问题更像是一个通用的对齐问题。

在我将这个新过滤器添加为 这就是 git repo 视图在此更改后加载时的样子

最大化视图后,它看起来像这样。这里对齐出错了。过滤器工具栏位于中心。

然后,如果我将其最小化,过滤器工具栏就会从视图中消失。

代码已更改

public void createPartControl(Composite aParent) {
        Composite displayArea = new Composite(aParent, SWT.NONE);
        displayArea.setLayout(new GridLayout());

        displayArea.setLayoutData(new GridData(SWT.FILL,6));


        final Composite temp = new Composite(displayArea, SWT.FILL);//XXX

        layout = new StackLayout();
        temp.setLayout(layout);
        createEmptyArea(temp);

        super.createPartControl(temp);

        IWorkbenchWindow w = PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow();
        ICommandService csrv = (ICommandService) w
                .getService(ICommandService.class);
        Command command = csrv
                .getCommand("org.eclipse.egit.ui.RepositoriesLinkWithSelection"); //$NON-NLS-1$
        reactOnSelection = (Boolean) command.getState(
                RegistryToggleState.STATE_ID).getValue();

        GridDataFactory.fillDefaults().grab(true, true).applyTo(temp);//XXX
//      GridDataFactory.fillDefaults().grab(true, true).applyTo(displayArea);//XXX
        filterToolbar = new FilterToolbar(this, displayArea);
        IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) getSite()
                .getService(IWorkbenchSiteProgressService.class);
        if (service != null) {
            service.showBusyForFamily(JobFamilies.REPO_VIEW_REFRESH);
            service.showBusyForFamily(JobFamilies.CLONE);
        }
    }

【问题讨论】:

  • 您可以尝试重置透视图:Window > Reset Perspective。以及代码与对齐有何关系?
  • @aly 我实际上想将过滤器框的位置固定在视图的底部。这样当我最大化视图或最小化视图时,它会与底部对齐
  • 向下滚动能看到底部的过滤框吗?在缺少过滤器框的第三张图像中,有一个可用的滚动条。向下滚动是否看到过滤器栏?
  • 过滤框实际上超出了可滚动区域。因此,我唯一可以查看过滤器的时间是在第一个视图(视图加载)或图像中。一旦我展开它,repo view scroll area 就会将其向下推,我必须最大化视图才能看到过滤框
  • 检查树上是否设置了一些 minHeight(在 GridData 中),这可能会迫使树占用足够的空间以使过滤器框被剪掉。

标签: java eclipse eclipse-plugin alignment


【解决方案1】:

正如@WaqasIlyas 所提到的,我今天大部分时间都在尝试GridData 中的参数,并且碰巧按照你所说的那样工作

public void createPartControl(Composite aParent) {
        Composite displayArea = new Composite(aParent, SWT.FILL);
        displayArea.setLayout(new GridLayout());
        displayArea.setLayoutData(new GridData(GridData.FILL,GridData.FILL, true, true));
        Composite historyComposite = new Composite(displayArea, SWT.NONE);

        layout = new StackLayout();
        historyComposite.setLayout(layout);
        historyComposite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL,GridData.VERTICAL_ALIGN_FILL, true, true));
        createEmptyArea(historyComposite);

        super.createPartControl(historyComposite);

        IWorkbenchWindow w = PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow();
        ICommandService csrv = (ICommandService) w
                .getService(ICommandService.class);
        Command command = csrv
                .getCommand("org.eclipse.egit.ui.RepositoriesLinkWithSelection"); //$NON-NLS-1$
        reactOnSelection = (Boolean) command.getState(
                RegistryToggleState.STATE_ID).getValue();
//XXX added this code and changed the position of some statement to make it work
        GridDataFactory.fillDefaults().grab(true, true).applyTo(historyComposite);
        filterToolbar = new FilterToolbar(this, displayArea);
        ((GridData) filterToolbar.getLayoutData()).verticalAlignment = SWT.END;
        Point computeSize = filterToolbar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        ((GridData) filterToolbar.getLayoutData()).minimumWidth = computeSize.x;
        ((GridData) filterToolbar.getLayoutData()).minimumHeight = computeSize.y;
        GridDataFactory.fillDefaults().grab(true, true).align(GridData.FILL, GridData.FILL).applyTo(displayArea);
//xxx code change ends
        IWorkbenchSiteProgressService service = (IWorkbenchSiteProgressService) getSite()
                .getService(IWorkbenchSiteProgressService.class);
        if (service != null) {
            service.showBusyForFamily(JobFamilies.REPO_VIEW_REFRESH);
            service.showBusyForFamily(JobFamilies.CLONE);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多