提交 76233b64 编写于 作者: J jurgen

Composite dialog pages model

上级 fdbb08a7
/*
* Copyright (C) 2010-2012 Serge Rieder
* serge@jkiss.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.jkiss.dbeaver.ext.ui;
import org.eclipse.jface.dialogs.IDialogPage;
/**
* ICompositeDialogPage
*/
public interface ICompositeDialogPage extends IDialogPage
{
IDialogPage[] getSubPages();
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
package org.jkiss.dbeaver.ext.ui;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.operation.IRunnableContext;
import org.jkiss.dbeaver.model.DBPConnectionInfo;
import org.jkiss.dbeaver.model.DBPDriver;
......@@ -38,7 +39,5 @@ public interface IDataSourceConnectionEditorSite
void updateMessage();
void testConnection();
boolean openDriverEditor();
}
......@@ -38,7 +38,9 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWizard;
import org.jkiss.dbeaver.ext.ui.ICompositeDialogPage;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
......@@ -113,27 +115,8 @@ public class MultiPageWizardDialog extends TitleAreaDialog implements IWizardCon
Point maxSize = new Point(0, 0);
IWizardPage[] pages = wizard.getPages();
for (int i = 0, pagesLength = pages.length; i < pagesLength; i++) {
IDialogPage page = pages[i];
page.createControl(pageArea);
if (i == 0 && page instanceof ActiveWizardPage) {
((ActiveWizardPage) page).activatePage();
}
Control control = page.getControl();
Point pageSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (pageSize.x > maxSize.x) maxSize.x = pageSize.x;
if (pageSize.y > maxSize.y) maxSize.y = pageSize.y;
GridData gd = (GridData) control.getLayoutData();
if (gd == null) {
gd = new GridData(GridData.FILL_BOTH);
control.setLayoutData(gd);
}
gd.exclude = i > 0;
control.setVisible(i == 0);
TreeItem item = new TreeItem(pagesTree, SWT.NONE);
item.setText(page.getTitle());
item.setData(page);
for (IWizardPage page : pages) {
addPage(null, page, maxSize);
}
prevPage = (IDialogPage) pagesTree.getItem(0).getData();
GridData gd = (GridData) pageArea.getLayoutData();
......@@ -171,6 +154,42 @@ public class MultiPageWizardDialog extends TitleAreaDialog implements IWizardCon
return composite;
}
private TreeItem addPage(TreeItem parentItem, IDialogPage page, Point maxSize)
{
boolean hasPages = pagesTree.getItemCount() != 0;
page.createControl(pageArea);
if (!hasPages && page instanceof ActiveWizardPage) {
((ActiveWizardPage) page).activatePage();
}
Control control = page.getControl();
Point pageSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
if (pageSize.x > maxSize.x) maxSize.x = pageSize.x;
if (pageSize.y > maxSize.y) maxSize.y = pageSize.y;
GridData gd = (GridData) control.getLayoutData();
if (gd == null) {
gd = new GridData(GridData.FILL_BOTH);
control.setLayoutData(gd);
}
gd.exclude = hasPages;
control.setVisible(!gd.exclude);
TreeItem item = parentItem == null ?
new TreeItem(pagesTree, SWT.NONE) :
new TreeItem(parentItem, SWT.NONE);
item.setText(page.getTitle());
item.setData(page);
// Ad sub pages
if (page instanceof ICompositeDialogPage) {
IDialogPage[] subPages = ((ICompositeDialogPage) page).getSubPages();
for (IDialogPage subPage : subPages) {
addPage(item, subPage, maxSize);
}
}
return item;
}
private void changePage()
{
pageArea.setRedraw(false);
......@@ -220,20 +239,23 @@ public class MultiPageWizardDialog extends TitleAreaDialog implements IWizardCon
@Override
public IWizardPage getCurrentPage()
{
return null;
TreeItem[] selection = pagesTree.getSelection();
if (CommonUtils.isEmpty(selection)) {
return null;
}
IDialogPage page = (IDialogPage)selection[0].getData();
return page instanceof IWizardPage ? (IWizardPage) page : null;
}
@Override
public void showPage(IWizardPage page)
{
/*
for (CTabItem item : pagesFolder.getItems()) {
for (TreeItem item : pagesTree.getItems()) {
if (item.getData() == page) {
pagesFolder.setSelection(item);
pagesTree.setSelection(item);
break;
}
}
*/
}
@Override
......
......@@ -190,15 +190,6 @@ class ConnectionPageSettings extends ActiveWizardPage<ConnectionWizard> implemen
getWizard().getContainer().updateTitleBar();
}
@Override
public void testConnection()
{
if (this.connectionEditor != null) {
this.connectionEditor.saveSettings();
this.wizard.testConnection();
}
}
@Override
public boolean openDriverEditor()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册