1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 20:35:38 +02:00

Completed 167551, wizard to export index for use in other workspaces.

This commit is contained in:
Markus Schorn 2007-03-19 15:17:58 +00:00
parent e45328dc4f
commit 29eec1d60a
12 changed files with 472 additions and 11 deletions

View file

@ -84,25 +84,26 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable {
PDOMManager pdomManager= CCoreInternals.getPDOMManager();
// wait for indexer
monitor.beginTask(Messages.TeamPDOMExportOperation_taskExportIndex, 100);
pdomManager.joinIndexer(Integer.MAX_VALUE, subMonitor(monitor, 80));
monitor.beginTask("", 100); //$NON-NLS-1$
pdomManager.joinIndexer(Integer.MAX_VALUE, subMonitor(monitor, 1));
checkMonitor(monitor);
// create index
IIndexLocationConverter converter= new ResourceContainerRelativeLocationConverter(ResourcesPlugin.getWorkspace().getRoot());
monitor.subTask(Messages.TeamPDOMExportOperation_subtaskCreateDatabase);
pdomManager.exportProjectPDOM(fProject, tmpPDOM, converter);
checkMonitor(monitor);
monitor.worked(5);
// create checksums
PDOM pdom= new PDOM(tmpPDOM, converter);
createChecksums(fProject, pdom, tmpChecksums, subMonitor(monitor, 10));
monitor.setTaskName(Messages.Checksums_taskComputeChecksums);
createChecksums(fProject, pdom, tmpChecksums, subMonitor(monitor, 94));
// create archive
createArchive(tmpPDOM, tmpChecksums);
// store preferences
monitor.setTaskName(Messages.TeamPDOMExportOperation_taskExportIndex);
IndexerPreferences.setIndexImportLocation(fProject.getProject(), fTargetLocation.toString());
}
finally {

View file

@ -302,12 +302,22 @@ public class IndexerPreferences {
}
public static String getIndexImportLocation(IProject project) {
Preferences[] prefs= new Preferences[] {
getProjectPreferences(project),
getInstancePreferences(),
getConfigurationPreferences(),
getDefaultPreferences()
};
Preferences[] prefs;
if (project != null) {
prefs= new Preferences[] {
getProjectPreferences(project),
getInstancePreferences(),
getConfigurationPreferences(),
getDefaultPreferences()
};
}
else {
prefs= new Preferences[] {
getInstancePreferences(),
getConfigurationPreferences(),
getDefaultPreferences()
};
}
return Platform.getPreferencesService().get(KEY_INDEX_IMPORT_LOCATION, DEFAULT_INDEX_IMPORT_LOCATION, prefs);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

@ -399,4 +399,7 @@ SpecificContentAssist.param= type
cViewScope.name = In C/C++ Views
cViewScope.description = In C/C++ Views
NewCfgDialog.name = newCfgDialog
NewCfgDialog.name = newCfgDialog
teamProjectIndexExportWizard.name = Team Shared Index
teamProjectIndexExportWizard.description = Exports C/C++ index for use in other workspaces.
exportWizard.CDTCategory.name = C/C++

View file

@ -1942,5 +1942,25 @@
properties="isSource"
type="org.eclipse.core.resources.IFile"/>
</extension>
<extension
point="org.eclipse.ui.exportWizards">
<wizard
category="org.eclipse.cdt.ui.exportWizardCategory"
class="org.eclipse.cdt.internal.ui.wizards.indexwizards.TeamProjectIndexExportWizard"
icon="icons/etool16/exportzip_wiz.gif"
id="org.eclipse.cdt.ui.teamSharedIndexWizard"
name="%teamProjectIndexExportWizard.name">
<selection
class="org.eclipse.core.resources.IProject">
</selection>
<description>
%teamProjectIndexExportWizard.description
</description>
</wizard>
<category
id="org.eclipse.cdt.ui.exportWizardCategory"
name="%exportWizard.CDTCategory.name">
</category>
</extension>
</plugin>

View file

@ -263,6 +263,7 @@ public class CPluginImages {
public static final ImageDescriptor DESC_WIZBAN_NEW_HEADERFILE= create(T_WIZBAN, "newhfile_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_NEW_SOURCEFILE= create(T_WIZBAN, "newcfile_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_NEWSRCFOLDR= create(T_WIZBAN, "newsrcfldr_wiz.gif"); //$NON-NLS-1$
public static final ImageDescriptor DESC_WIZBAN_EXPORTINDEX= create(T_WIZBAN, "exportzip_wiz.png"); //$NON-NLS-1$
public static final ImageDescriptor DESC_TOOL_NEWCLASS= create(T_TOOL, "newclass_wiz.gif"); //$NON-NLS-1$

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.indexwizards;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.wizards.indexwizards.messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.indexwizards;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.CPluginImages;
public class TeamProjectIndexExportWizard extends Wizard implements IExportWizard {
private static final String DIALOG_SETTINGS_SECTION = "TeamProjectIndexExportWizard"; //$NON-NLS-1$
private TeamProjectIndexExportWizardPage fMainPage;
private IStructuredSelection fSelection;
public TeamProjectIndexExportWizard() {
IDialogSettings workbenchSettings = CUIPlugin.getDefault().getDialogSettings();
IDialogSettings section = workbenchSettings.getSection(DIALOG_SETTINGS_SECTION);
if (section == null) {
section = workbenchSettings.addNewSection(DIALOG_SETTINGS_SECTION);
}
setDialogSettings(section);
}
public void addPages() {
super.addPages();
fMainPage = new TeamProjectIndexExportWizardPage(fSelection);
addPage(fMainPage);
}
public boolean performFinish() {
return fMainPage.finish();
}
public void init(IWorkbench workbench, IStructuredSelection selection) {
fSelection= selection;
setWindowTitle(Messages.getString("TeamProjectIndexExportWizard.title")); //$NON-NLS-1$
setDefaultPageImageDescriptor(CPluginImages.DESC_WIZBAN_EXPORTINDEX);
setNeedsProgressMonitor(true);
}
}

View file

@ -0,0 +1,320 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards.indexwizards;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.WizardDataTransferPage;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.ui.CElementLabelProvider;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.pdom.TeamPDOMExportOperation;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.cdt.internal.ui.viewsupport.ListContentProvider;
public class TeamProjectIndexExportWizardPage extends WizardDataTransferPage implements Listener {
private IStructuredSelection fInitialSelection;
private CheckboxTableViewer fProjectViewer;
private Text fDestinationField;
/**
* Create an instance of this class
*/
protected TeamProjectIndexExportWizardPage(String name, IStructuredSelection selection) {
super(name);
fInitialSelection= selection;
}
/**
* Create an instance of this class.
*
* @param selection the selection
*/
public TeamProjectIndexExportWizardPage(IStructuredSelection selection) {
this("indexExportPage", selection); //$NON-NLS-1$
setTitle(Messages.getString("TeamProjectIndexExportWizardPage.title")); //$NON-NLS-1$
setDescription(Messages.getString("TeamProjectIndexExportWizardPage.description")); //$NON-NLS-1$
}
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
| GridData.HORIZONTAL_ALIGN_FILL));
composite.setFont(parent.getFont());
createResourcesGroup(composite);
// createButtonsGroup(composite);
createDestinationGroup(composite);
// createOptionsGroup(composite);
restoreWidgetValues();
if (fInitialSelection != null) {
setupBasedOnInitialSelections();
}
setupDestination();
updateWidgetEnablements();
setPageComplete(determinePageCompletion());
setErrorMessage(null); // should not initially have error message
setControl(composite);
giveFocusToDestination();
}
/**
* Creates the checkbox tree and list for selecting resources.
*
* @param parent the parent control
*/
protected final void createResourcesGroup(Composite parent) {
Composite resourcesGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
resourcesGroup.setLayout(layout);
resourcesGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
resourcesGroup.setFont(parent.getFont());
Table table= new Table(resourcesGroup, SWT.CHECK | SWT.BORDER);
table.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fProjectViewer= new CheckboxTableViewer(table);
fProjectViewer.setContentProvider(new ListContentProvider());
fProjectViewer.setLabelProvider(new CElementLabelProvider());
ICheckStateListener listener = new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
updateWidgetEnablements();
}
};
fProjectViewer.addCheckStateListener(listener);
initProjects();
}
private void initProjects() {
ArrayList input = new ArrayList();
ICProject[] projects;
try {
projects = CoreModel.getDefault().getCModel().getCProjects();
for (int i = 0; i < projects.length; i++) {
if (projects[i].getProject().isOpen()) {
input.add(projects[i]);
}
}
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
}
fProjectViewer.setInput(input);
}
private void setupBasedOnInitialSelections() {
HashSet names= new HashSet();
Iterator it = fInitialSelection.iterator();
while (it.hasNext()) {
IProject project = (IProject) it.next();
names.add(project.getName());
}
Collection prjs= (Collection) fProjectViewer.getInput();
for (Iterator iterator = prjs.iterator(); iterator.hasNext();) {
ICProject prj = (ICProject) iterator.next();
if (names.contains(prj.getElementName())) {
fProjectViewer.setChecked(prj, true);
}
}
}
private void setupDestination() {
String dest;
ICProject[] prjs= getCheckedElements();
if (prjs.length > 0) {
dest= IndexerPreferences.getIndexImportLocation(prjs[0].getProject());
}
else {
dest= IndexerPreferences.getIndexImportLocation(null);
}
fDestinationField.setText(dest);
}
private void createDestinationGroup(Composite parent) {
Font font = parent.getFont();
// destination specification group
Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
destinationSelectionGroup.setLayout(layout);
destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
destinationSelectionGroup.setFont(font);
Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
destinationLabel.setText(Messages.getString("TeamProjectIndexExportWizardPage.destinationLabel")); //$NON-NLS-1$
destinationLabel.setFont(font);
// destination name entry field
fDestinationField = new Text(destinationSelectionGroup, SWT.BORDER);
fDestinationField.addListener(SWT.Modify, this);
fDestinationField.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
fDestinationField.setLayoutData(data);
fDestinationField.setFont(font);
new Label(parent, SWT.NONE); // vertical spacer
}
public boolean finish() {
ICProject[] projectsToExport= getCheckedElements();
// about to invoke the operation so save our state
saveWidgetValues();
return executeExportOperation(projectsToExport);
}
private ICProject[] getCheckedElements() {
Object[] obj= fProjectViewer.getCheckedElements();
ICProject[] prjs= new ICProject[obj.length];
System.arraycopy(obj, 0, prjs, 0, obj.length);
return prjs;
}
private boolean executeExportOperation(final ICProject[] projects) {
final String dest= getDestinationValue();
final MultiStatus status= new MultiStatus(CUIPlugin.PLUGIN_ID,
0, Messages.getString("TeamProjectIndexExportWizardPage.errorWhileExporting"), null); //$NON-NLS-1$
IRunnableWithProgress op= new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", projects.length); //$NON-NLS-1$
for (int i = 0; i < projects.length; i++) {
ICProject project = projects[i];
TeamPDOMExportOperation op= new TeamPDOMExportOperation(project);
op.setTargetLocation(dest);
try {
op.run(new SubProgressMonitor(monitor, 1));
} catch (CoreException e) {
status.merge(e.getStatus());
}
}
}
};
try {
getContainer().run(true, true, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
displayErrorDialog(e.getTargetException());
return false;
}
if (!status.isOK()) {
ErrorDialog.openError(getContainer().getShell(),
getErrorDialogTitle(),
null, // no special message
status);
return false;
}
return true;
}
private String getDestinationValue() {
return fDestinationField.getText().trim();
}
private void giveFocusToDestination() {
fDestinationField.setFocus();
}
/**
* Answer a boolean indicating whether the receivers destination specification
* widgets currently all contain valid values.
*/
protected boolean validateDestinationGroup() {
String destinationValue = getDestinationValue();
if (destinationValue.length() == 0) {
setMessage(Messages.getString("TeamProjectIndexExportWizardPage.noDestination")); //$NON-NLS-1$
return false;
}
setErrorMessage(null);
return true;
}
protected boolean validateSourceGroup() {
// there must be some resources selected for Export
boolean isValid = true;
Object[] projectsToExport = getCheckedElements();
if (projectsToExport.length == 0){
setErrorMessage(Messages.getString("TeamProjectIndexExportWizardPage.noSelection")); //$NON-NLS-1$
isValid = false;
} else {
setErrorMessage(null);
}
return super.validateSourceGroup() && isValid;
}
protected void updateWidgetEnablements() {
boolean pageComplete = determinePageCompletion();
setPageComplete(pageComplete);
if (pageComplete) {
setMessage(null);
}
super.updateWidgetEnablements();
}
public void handleEvent(Event event) {
updateWidgetEnablements();
}
protected String getErrorDialogTitle() {
return Messages.getString("TeamProjectIndexExportWizardPage.errorDlgTitle"); //$NON-NLS-1$
}
protected boolean allowNewContainerName() {
return false;
}
}

View file

@ -0,0 +1,18 @@
###############################################################################
# Copyright (c) 2007 Wind River Systems, Inc. and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Markus Schorn (Wind River Systems)
###############################################################################
TeamProjectIndexExportWizard.title=Export
TeamProjectIndexExportWizardPage.title=C/C++ index
TeamProjectIndexExportWizardPage.description=Export C/C++ index for use in other workspaces.
TeamProjectIndexExportWizardPage.destinationLabel=Export destination:
TeamProjectIndexExportWizardPage.errorWhileExporting=Errors occurred while exporting index
TeamProjectIndexExportWizardPage.noDestination=Enter a destination archive file.
TeamProjectIndexExportWizardPage.noSelection=At least one project must be selected.
TeamProjectIndexExportWizardPage.errorDlgTitle=Export C/C++ Index