1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

new C project options controls

This commit is contained in:
David Inglis 2003-08-13 19:26:27 +00:00
parent 9685903f5f
commit 4c82ed5537
6 changed files with 426 additions and 76 deletions

View file

@ -12,17 +12,27 @@ package org.eclipse.cdt.ui;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public abstract class AbstractCOptionPage implements ICOptionPage {
public abstract class AbstractCOptionPage extends DialogPage implements ICOptionPage {
private String fErrorMessage;
private String fMessage;
private boolean bIsValid = true;
private Control fControl;
private ICOptionContainer fContainer;
public AbstractCOptionPage() {
super();
}
public AbstractCOptionPage(String title) {
super(title);
}
public AbstractCOptionPage(String title, ImageDescriptor image) {
super(title, image);
}
public void setContainer(ICOptionContainer container) {
fContainer = container;
@ -32,22 +42,6 @@ public abstract class AbstractCOptionPage implements ICOptionPage {
return fContainer;
}
public Image getImage() {
return null;
}
public abstract void createControl(Composite parent);
public abstract String getLabel();
public Control getControl() {
return fControl;
}
protected void setControl(Control control) {
fControl = control;
}
protected void setValid(boolean isValid) {
bIsValid = isValid;
}
@ -56,28 +50,10 @@ public abstract class AbstractCOptionPage implements ICOptionPage {
return bIsValid;
}
public String getMessage() {
return fMessage;
}
protected void setMessage(String message) {
fMessage = message;
}
public String getErrorMessage() {
return fErrorMessage;
}
protected void setErrorMessage(String message) {
fErrorMessage = message;
}
public void setVisible(boolean visible) {
}
public abstract void performApply(IProgressMonitor monitor) throws CoreException;
public void performDefaults() {
}
public abstract void performDefaults();
public abstract void createControl(Composite parent);
}

View file

@ -0,0 +1,149 @@
package org.eclipse.cdt.ui;
/***********************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
public class BinaryParserBlock extends AbstractCOptionPage {
private static String[][] radios;
protected Combo comboBox;
private HashMap idMap = new HashMap();
private String initial;
private Preferences fPrefs;
public BinaryParserBlock(Preferences prefs) {
super("Binary Parser");
setDescription("Set required binary parser for this project");
fPrefs = prefs;
}
public void createControl(Composite parent) {
Composite control = ControlFactory.createComposite(parent, 2);
((GridLayout)control.getLayout()).makeColumnsEqualWidth = false;
((GridLayout)control.getLayout()).marginWidth = 5;
ControlFactory.createEmptySpace(control, 2);
Label label = ControlFactory.createLabel(control, "Binary Parser:");
label.setLayoutData(new GridData());
comboBox = new Combo(control, SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gd = new GridData(GridData.GRAB_HORIZONTAL);
gd.grabExcessHorizontalSpace = true;
comboBox.setLayoutData(gd);
comboBox.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
getContainer().updateContainer();
}
});
Iterator items = idMap.keySet().iterator();
while( items.hasNext()) {
comboBox.add((String)items.next());
}
if (initial != null) {
comboBox.setText(initial);
}
setControl(control);
}
public void performApply(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Parsers", 1);
if (getContainer().getProject() != null) {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(getContainer().getProject());
String selected = comboBox.getText();
if (selected != null) {
if (initial == null || !selected.equals(initial)) {
desc.remove(CCorePlugin.BINARY_PARSER_UNIQ_ID);
desc.create(CCorePlugin.BINARY_PARSER_UNIQ_ID, (String)idMap.get(initial));
CCorePlugin.getDefault().getCoreModel().resetBinaryParser(getContainer().getProject());
initial = selected;
}
}
} else {
fPrefs.setDefault(CCorePlugin.PREF_BINARY_PARSER, (String)idMap.get(initial));
}
}
public void setContainer(ICOptionContainer container) {
super.setContainer(container);
IExtensionPoint point = CCorePlugin.getDefault().getDescriptor().getExtensionPoint(CCorePlugin.BINARY_PARSER_SIMPLE_ID);
if (point != null) {
IExtension[] exts = point.getExtensions();
radios = new String[exts.length][2];
for (int i = 0; i < exts.length; i++) {
idMap.put(exts[i].getLabel(), exts[i].getUniqueIdentifier());
}
}
if (getContainer().getProject() != null) {
try {
ICDescriptor desc = CCorePlugin.getDefault().getCProjectDescription(getContainer().getProject());
ICExtensionReference[] ref = desc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID);
if (ref.length > 0) {
initial = point.getExtension(ref[0].getID()).getLabel();
}
} catch (CoreException e) {
}
}
if (initial == null) {
String id = fPrefs.getString(CCorePlugin.PREF_BINARY_PARSER);
if (id == null || id.length() == 0) {
initial = point.getExtension(CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID).getLabel();
} else {
initial = point.getExtension(id).getLabel();
}
}
}
public void performDefaults() {
IExtensionPoint point = CCorePlugin.getDefault().getDescriptor().getExtensionPoint(CCorePlugin.BINARY_PARSER_SIMPLE_ID);
String id;
if (getContainer().getProject() != null) {
id = fPrefs.getString(CCorePlugin.PREF_BINARY_PARSER);
} else {
id = fPrefs.getDefaultString(CCorePlugin.PREF_BINARY_PARSER);
}
if (id == null || id.length() == 0) {
initial = point.getExtension(CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID).getLabel();
} else {
initial = point.getExtension(id).getLabel();
}
comboBox.setText(initial);
getContainer().updateContainer();
}
}

View file

@ -12,30 +12,14 @@ package org.eclipse.cdt.ui;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.jface.dialogs.IDialogPage;
public interface ICOptionPage {
public interface ICOptionPage extends IDialogPage {
public void setContainer(ICOptionContainer container);
public String getLabel();
public Image getImage();
public void createControl(Composite parent);
public Control getControl();
public boolean isValid();
public String getMessage();
public String getErrorMessage();
public void setVisible(boolean visible);
public void performApply(IProgressMonitor monitor) throws CoreException;
public void performDefaults();

View file

@ -0,0 +1,97 @@
package org.eclipse.cdt.ui;
/***********************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IndexModel;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.sourcedependency.DependencyManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
public class IndexerBlock extends AbstractCOptionPage {
private Button indexerSwitch;
private Button indexerSwitch2;
private Button dTreeSwitch;
public IndexerBlock() {
super("Indexer");
setDescription("Project Indexer option");
}
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout grid = new GridLayout();
grid.numColumns = 1;
composite.setLayout(grid);
indexerSwitch = new Button(composite, SWT.CHECK | SWT.RIGHT);
indexerSwitch.setAlignment(SWT.LEFT);
indexerSwitch.setText("Enable CTAGS indexing service for this project");
indexerSwitch2 = new Button(composite, SWT.CHECK | SWT.RIGHT);
indexerSwitch2.setAlignment(SWT.LEFT);
indexerSwitch2.setText("Enable NEW indexing service for this project");
dTreeSwitch = new Button(composite, SWT.CHECK | SWT.RIGHT);
dTreeSwitch.setAlignment(SWT.LEFT);
dTreeSwitch.setText("Enable dependency tree service for this project");
IProject project = getContainer().getProject();
if (project != null) {
IndexModel indexer = CCorePlugin.getDefault().getIndexModel();
IndexManager newIndexer = CCorePlugin.getDefault().getCoreModel().getIndexManager();
if (indexerSwitch != null) {
//indexerSwitch.setAlignment(SWT.LEFT);
//indexerSwitch.setText("Enable indexing service for this project");
indexerSwitch.setSelection(indexer.isEnabled(project));
}
if (indexerSwitch2 != null) {
indexerSwitch2.setSelection(newIndexer.isEnabled(project));
}
DependencyManager depManager = CCorePlugin.getDefault().getCoreModel().getDependencyManager();
if (dTreeSwitch != null) {
dTreeSwitch.setSelection(depManager.isEnabled(project));
}
}
setControl(composite);
}
public void performApply(IProgressMonitor monitor) throws CoreException {
IProject project = getContainer().getProject();
if (project != null) {
IndexModel indexer = CCorePlugin.getDefault().getIndexModel();
indexer.setEnabled(project, indexerSwitch.getSelection());
IndexManager newIndexer = CCorePlugin.getDefault().getCoreModel().getIndexManager();
newIndexer.setEnabled(project, indexerSwitch2.getSelection());
DependencyManager depManager = CCorePlugin.getDefault().getCoreModel().getDependencyManager();
depManager.setEnabled(project, dTreeSwitch.getSelection());
}
}
public void performDefaults() {
if (getContainer().getProject() != null) {
indexerSwitch.setSelection(false);
indexerSwitch2.setSelection(false);
dTreeSwitch.setSelection(false);
}
}
}

View file

@ -0,0 +1,146 @@
package org.eclipse.cdt.ui;
/***********************************************************************
* Copyright (c) 2003 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v05.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
public class ReferenceBlock extends AbstractCOptionPage {
private static final String PREFIX = "ReferenceBlock"; // $NON-NLS-1$
private static final String LABEL = PREFIX + ".label"; // $NON-NLS-1$
private static final String DESC = PREFIX + ".desc"; // $NON-NLS-1$
private CheckboxTableViewer referenceProjectsViewer;
public ReferenceBlock() {
super(CUIPlugin.getResourceString(LABEL));
setDescription(CUIPlugin.getResourceString(DESC));
}
public Image getImage() {
return CPluginImages.get(CPluginImages.IMG_OBJS_PROJECT);
}
/**
* Returns a content provider for the reference project
* viewer. It will return all projects in the workspace.
*
* @return the content provider
*/
protected IStructuredContentProvider getContentProvider() {
return new WorkbenchContentProvider() {
public Object[] getChildren(Object element) {
if (!(element instanceof IWorkspace))
return new Object[0];
ArrayList aList = new ArrayList(15);
final IProject[] projects = ((IWorkspace)element).getRoot().getProjects();
for (int i = 0; i < projects.length; i++) {
if (CoreModel.getDefault().hasCNature(projects[i])) {
// Do not show the actual project being look at
if ((getContainer().getProject() != null) && getContainer().getProject().equals(projects[i])) {
continue;
}
aList.add(projects[i]);
}
}
return aList.toArray();
}
};
}
protected void initializeValues () {
if (getContainer().getProject() != null) {
try {
IProject[] referenced = getContainer().getProject().getReferencedProjects();
referenceProjectsViewer.setCheckedElements(referenced);
} catch (CoreException e) {
}
}
}
/**
* Returns the referenced projects selected by the user.
*
* @return the referenced projects
*/
public IProject[] getReferencedProjects() {
Object[] elements = referenceProjectsViewer.getCheckedElements();
IProject[] projects = new IProject[elements.length];
System.arraycopy(elements, 0, projects, 0, elements.length);
return projects;
}
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label label = new Label(composite, SWT.LEFT);
label.setText(CUIPlugin.getResourceString(DESC));
GridData lbldata = new GridData(GridData.FILL_HORIZONTAL);
lbldata.horizontalSpan = 1;
label.setLayoutData(lbldata);
referenceProjectsViewer = ControlFactory.createListViewer
(composite, null, SWT.DEFAULT, SWT.DEFAULT, GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
referenceProjectsViewer.setLabelProvider(new WorkbenchLabelProvider());
referenceProjectsViewer.setContentProvider(getContentProvider());
referenceProjectsViewer.setInput(ResourcesPlugin.getWorkspace());
initializeValues();
setControl(composite);
}
public void performApply(IProgressMonitor monitor) throws CoreException {
IProject[] refProjects = getReferencedProjects();
if (refProjects != null) {
IProject project = getContainer().getProject();
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("Reference Projects", 1);
try {
IProjectDescription description = project.getDescription();
description.setReferencedProjects(refProjects);
project.setDescription(description, new SubProgressMonitor(monitor, 1));
} catch (CoreException e) {
}
}
}
public void performDefaults() {
initializeValues();
}
}

View file

@ -18,8 +18,8 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -35,7 +35,7 @@ public abstract class TabFolderOptionBlock {
private Label messageLabel;
private TabItem fCurrentItem;
private TabFolder folder;
private TabFolder fFolder;
private ArrayList tabs;
private ICOptionContainer fParent;
@ -47,14 +47,14 @@ public abstract class TabFolderOptionBlock {
if (tabs == null) {
tabs = new ArrayList();
}
TabItem item = new TabItem(folder, SWT.NONE);
item.setText(tab.getLabel());
TabItem item = new TabItem(fFolder, SWT.NONE);
item.setText(tab.getTitle());
Image img = tab.getImage();
if (img != null)
item.setImage(img);
item.setData(tab);
tab.setContainer(fParent);
tab.createControl(folder);
tab.createControl(item.getParent());
item.setControl(tab.getControl());
tabs.add(tab);
return item;
@ -72,22 +72,20 @@ public abstract class TabFolderOptionBlock {
Label separator = new Label(composite, SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
folder = new TabFolder(composite, SWT.NONE);
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
folder.setLayout(new TabFolderLayout());
fFolder = new TabFolder(composite, SWT.NONE);
fFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
fFolder.setLayout(new TabFolderLayout());
fCurrentItem = addTabs();
folder.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
fFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
fCurrentItem = (TabItem) e.item;
fParent.updateContainer();
}
});
messageLabel.setText(((ICOptionPage) tabs.get(0)).getMessage());
messageLabel.setText(((ICOptionPage) tabs.get(0)).getDescription());
return composite;
}
@ -100,7 +98,7 @@ public abstract class TabFolderOptionBlock {
try {
tab.performApply(new NullProgressMonitor());
} catch (CoreException e) {
CUIPlugin.errorDialog(folder.getShell(), "Error", "Error setting options", e);
CUIPlugin.errorDialog(fFolder.getShell(), "Error", "Error setting options", e);
return false;
}
}
@ -117,7 +115,7 @@ public abstract class TabFolderOptionBlock {
tab.setVisible(visible);
}
update();
folder.setFocus();
fFolder.setFocus();
}
public void update() {
@ -134,7 +132,7 @@ public abstract class TabFolderOptionBlock {
if (ok && fCurrentItem != null) {
setErrorMessage(null);
ICOptionPage tab = (ICOptionPage) fCurrentItem.getData();
messageLabel.setText(tab.getMessage());
messageLabel.setText(tab.getDescription());
}
setValid(ok);
}