mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
update so that it can be extended to use other type control
This commit is contained in:
parent
dc9fe084f3
commit
8c4b0d9020
1 changed files with 95 additions and 51 deletions
|
@ -12,6 +12,7 @@ package org.eclipse.cdt.ui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
|
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -30,23 +31,81 @@ import org.eclipse.swt.widgets.TabFolder;
|
||||||
import org.eclipse.swt.widgets.TabItem;
|
import org.eclipse.swt.widgets.TabItem;
|
||||||
|
|
||||||
public abstract class TabFolderOptionBlock {
|
public abstract class TabFolderOptionBlock {
|
||||||
|
private boolean initializingTabs = true;
|
||||||
|
private Composite composite;
|
||||||
|
private boolean bShowMessageArea;
|
||||||
private String fErrorMessage;
|
private String fErrorMessage;
|
||||||
private boolean bIsValid;
|
private boolean bIsValid;
|
||||||
|
|
||||||
private Label messageLabel;
|
private Label messageLabel;
|
||||||
private TabItem fCurrentItem;
|
private ArrayList pages;
|
||||||
private TabFolder fFolder;
|
protected ICOptionContainer fParent;
|
||||||
private ArrayList tabs;
|
private ICOptionPage fCurrentPage;
|
||||||
private ICOptionContainer fParent;
|
|
||||||
|
|
||||||
public TabFolderOptionBlock(ICOptionContainer parent) {
|
private TabFolder fFolder;
|
||||||
|
|
||||||
|
public TabFolderOptionBlock(ICOptionContainer parent, boolean showMessageArea) {
|
||||||
fParent = parent;
|
fParent = parent;
|
||||||
|
bShowMessageArea = showMessageArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TabFolderOptionBlock(ICOptionContainer parent) {
|
||||||
|
this(parent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TabItem addTab(ICOptionPage tab) {
|
protected void addOptionPage(ICOptionPage page) {
|
||||||
if (tabs == null) {
|
if (pages == null) {
|
||||||
tabs = new ArrayList();
|
pages = new ArrayList();
|
||||||
}
|
}
|
||||||
|
if (!pages.contains(page)) {
|
||||||
|
pages.add(page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List getOptionPages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Control createContents(Composite parent) {
|
||||||
|
|
||||||
|
composite = new Composite(parent, SWT.NONE);
|
||||||
|
composite.setLayout(new GridLayout(1, false));
|
||||||
|
|
||||||
|
if (bShowMessageArea) {
|
||||||
|
messageLabel = new Label(composite, SWT.LEFT);
|
||||||
|
messageLabel.setFont(composite.getFont());
|
||||||
|
messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
|
|
||||||
|
Label separator = new Label(composite, SWT.HORIZONTAL);
|
||||||
|
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
createFolder(composite);
|
||||||
|
|
||||||
|
addTabs();
|
||||||
|
setCurrentPage((ICOptionPage) pages.get(0));
|
||||||
|
initializingTabs = false;
|
||||||
|
String desc = ((ICOptionPage) pages.get(0)).getDescription();
|
||||||
|
if (desc != null) {
|
||||||
|
messageLabel.setText(desc);
|
||||||
|
}
|
||||||
|
return composite;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createFolder(Composite parent) {
|
||||||
|
fFolder = new TabFolder(parent, SWT.NONE);
|
||||||
|
fFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||||
|
fFolder.setLayout(new TabFolderLayout());
|
||||||
|
|
||||||
|
fFolder.addSelectionListener(new SelectionAdapter() {
|
||||||
|
public void widgetSelected(SelectionEvent e) {
|
||||||
|
setCurrentPage((ICOptionPage) ((TabItem) e.item).getData());
|
||||||
|
fParent.updateContainer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addTab(ICOptionPage tab) {
|
||||||
TabItem item = new TabItem(fFolder, SWT.NONE);
|
TabItem item = new TabItem(fFolder, SWT.NONE);
|
||||||
item.setText(tab.getTitle());
|
item.setText(tab.getTitle());
|
||||||
Image img = tab.getImage();
|
Image img = tab.getImage();
|
||||||
|
@ -56,49 +115,21 @@ public abstract class TabFolderOptionBlock {
|
||||||
tab.setContainer(fParent);
|
tab.setContainer(fParent);
|
||||||
tab.createControl(item.getParent());
|
tab.createControl(item.getParent());
|
||||||
item.setControl(tab.getControl());
|
item.setControl(tab.getControl());
|
||||||
tabs.add(tab);
|
addOptionPage(tab);
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Control createContents(Composite parent) {
|
abstract protected void addTabs();
|
||||||
|
|
||||||
Composite composite = new Composite(parent, SWT.NONE);
|
|
||||||
composite.setLayout(new GridLayout(1, false));
|
|
||||||
|
|
||||||
messageLabel = new Label(composite, SWT.LEFT);
|
public boolean performApply(IProgressMonitor monitor) {
|
||||||
messageLabel.setFont(composite.getFont());
|
if ( initializingTabs )
|
||||||
messageLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
return false;
|
||||||
|
Iterator iter = pages.iterator();
|
||||||
Label separator = new Label(composite, SWT.HORIZONTAL);
|
|
||||||
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
|
||||||
|
|
||||||
fFolder = new TabFolder(composite, SWT.NONE);
|
|
||||||
fFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
|
|
||||||
fFolder.setLayout(new TabFolderLayout());
|
|
||||||
|
|
||||||
fCurrentItem = addTabs();
|
|
||||||
|
|
||||||
fFolder.addSelectionListener(new SelectionAdapter() {
|
|
||||||
public void widgetSelected(SelectionEvent e) {
|
|
||||||
fCurrentItem = (TabItem) e.item;
|
|
||||||
fParent.updateContainer();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
messageLabel.setText(((ICOptionPage) tabs.get(0)).getDescription());
|
|
||||||
return composite;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract protected TabItem addTabs();
|
|
||||||
|
|
||||||
public boolean performOk(IProgressMonitor monitor) {
|
|
||||||
Iterator iter = tabs.iterator();
|
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
ICOptionPage tab = (ICOptionPage) iter.next();
|
ICOptionPage tab = (ICOptionPage) iter.next();
|
||||||
try {
|
try {
|
||||||
tab.performApply(new NullProgressMonitor());
|
tab.performApply(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CUIPlugin.errorDialog(fFolder.getShell(), "Error", "Error setting options", e);
|
CUIPlugin.errorDialog(composite.getShell(), "Error", "Error setting options", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,18 +140,21 @@ public abstract class TabFolderOptionBlock {
|
||||||
* @see DialogPage#setVisible(boolean)
|
* @see DialogPage#setVisible(boolean)
|
||||||
*/
|
*/
|
||||||
public void setVisible(boolean visible) {
|
public void setVisible(boolean visible) {
|
||||||
Iterator iter = tabs.iterator();
|
if ( initializingTabs )
|
||||||
|
return;
|
||||||
|
Iterator iter = pages.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
ICOptionPage tab = (ICOptionPage) iter.next();
|
ICOptionPage tab = (ICOptionPage) iter.next();
|
||||||
tab.setVisible(visible);
|
tab.setVisible(visible);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
fFolder.setFocus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
|
if ( initializingTabs )
|
||||||
|
return;
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
Iterator iter = tabs.iterator();
|
Iterator iter = pages.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
ICOptionPage tab = (ICOptionPage) iter.next();
|
ICOptionPage tab = (ICOptionPage) iter.next();
|
||||||
ok = tab.isValid();
|
ok = tab.isValid();
|
||||||
|
@ -129,10 +163,11 @@ public abstract class TabFolderOptionBlock {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ok && fCurrentItem != null) {
|
if (ok) {
|
||||||
setErrorMessage(null);
|
setErrorMessage(null);
|
||||||
ICOptionPage tab = (ICOptionPage) fCurrentItem.getData();
|
ICOptionPage tab = getCurrentPage();
|
||||||
messageLabel.setText(tab.getDescription());
|
if (bShowMessageArea && tab.getDescription() != null)
|
||||||
|
messageLabel.setText(tab.getDescription());
|
||||||
}
|
}
|
||||||
setValid(ok);
|
setValid(ok);
|
||||||
}
|
}
|
||||||
|
@ -154,8 +189,17 @@ public abstract class TabFolderOptionBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performDefaults() {
|
public void performDefaults() {
|
||||||
ICOptionPage tab = (ICOptionPage) fCurrentItem.getData();
|
if ( initializingTabs )
|
||||||
tab.performDefaults();
|
return;
|
||||||
|
getCurrentPage().performDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICOptionPage getCurrentPage() {
|
||||||
|
return fCurrentPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentPage(ICOptionPage page) {
|
||||||
|
fCurrentPage = page;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue