下面列出了org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider#org.eclipse.ui.internal.wizards.datatransfer.DataTransferMessages 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Collect the list of .project files that are under directory into files.
*
* @param files
* @param monitor
* The monitor to report to
* @return boolean <code>true</code> if the operation was completed.
*/
private boolean collectProjectFilesFromProvider(final Collection<ProjectRecord> files, final Object entry,
final int level, final IProgressMonitor monitor) {
if (monitor.isCanceled()) { return false; }
monitor.subTask(NLS.bind(DataTransferMessages.WizardProjectsImportPage_CheckingMessage,
structureProvider.getLabel(entry)));
List<?> children = structureProvider.getChildren(entry);
if (children == null) {
children = new ArrayList<>(1);
}
final Iterator<?> childrenEnum = children.iterator();
while (childrenEnum.hasNext()) {
final Object child = childrenEnum.next();
if (structureProvider.isFolder(child)) {
collectProjectFilesFromProvider(files, child, level + 1, monitor);
}
final String elementLabel = structureProvider.getLabel(child);
if (elementLabel.equals(IProjectDescription.DESCRIPTION_FILE_NAME)) {
files.add(new ProjectRecord(child, entry, level));
}
}
return true;
}
/**
* Attempts to ensure that the specified directory exists on the local file system. Answers a boolean indicating
* success.
* @return boolean
* @param directory
* java.io.File
*/
protected boolean ensureDirectoryExists(File directory) {
if (!directory.exists()) {
if (!queryYesNoQuestion(DataTransferMessages.DataTransfer_createTargetDirectory)) {
return false;
}
if (!directory.mkdirs()) {
displayErrorDialog(DataTransferMessages.DataTransfer_directoryCreationError);
giveFocusToDestination();
return false;
}
}
return true;
}
/**
* 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(destinationEmptyMessage());
return false;
}
String conflictingContainer = getConflictingContainerNameFor(destinationValue);
if (conflictingContainer == null) {
// no error message, but warning may exists
String threatenedContainer = getOverlappingProjectName(destinationValue);
if (threatenedContainer == null)
setMessage(null);
else
setMessage(NLS.bind(DataTransferMessages.FileExport_damageWarning, threatenedContainer), WARNING);
} else {
setErrorMessage(NLS.bind(DataTransferMessages.FileExport_conflictingContainer, conflictingContainer));
giveFocusToDestination();
return false;
}
return true;
}
/**
* Returns a boolean indicating whether the passed File handle is is valid and available for use.
*/
protected boolean ensureTargetFileIsValid(File targetFile) {
if (targetFile.exists() && targetFile.isDirectory()) {
displayErrorDialog(DataTransferMessages.ZipExport_mustBeFile);
giveFocusToDestination();
return false;
}
if (targetFile.exists()) {
if (targetFile.canWrite()) {
if (!queryYesNoQuestion(DataTransferMessages.ZipExport_alreadyExists)) {
return false;
}
} else {
displayErrorDialog(DataTransferMessages.ZipExport_alreadyExistsError);
giveFocusToDestination();
return false;
}
}
return true;
}
/**
* Open an appropriate destination browser so that the user can specify a source to import from
*/
protected void handleDestinationBrowseButtonPressed() {
FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET);
dialog.setFilterExtensions(new String[] { "*.hszip", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
dialog.setText(DataTransferMessages.ArchiveExport_selectDestinationTitle);
String currentSourceString = getDestinationValue();
int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
if (lastSeparatorIndex != -1) {
dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
}
String selectedFileName = dialog.open();
if (selectedFileName != null) {
setErrorMessage(null);
setDestinationValue(selectedFileName);
if (getWhiteCheckedResources().size() > 0) {
setDescription(null);
}
}
}
/**
* Constructor for ExternalProjectImportWizard.
*
* @param initialPath Default path for wizard to import
* @since 3.5
*/
public ImportProjectWizard(String initialPath)
{
super();
this.initialPath = initialPath;
setWindowTitle(DataTransferMessages.DataTransfer_importTitle);
setNeedsProgressMonitor(true);
IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault()
.getDialogSettings();
IDialogSettings wizardSettings = workbenchSettings
.getSection(IMPORT_PROJECT_SECTION);
if (wizardSettings == null) {
wizardSettings = workbenchSettings
.addNewSection(IMPORT_PROJECT_SECTION);
}
setDialogSettings(wizardSettings);
}
/**
* Attempts to ensure that the specified directory exists on the local file system. Answers a boolean indicating
* success.
* @return boolean
* @param directory
* java.io.File
*/
protected boolean ensureDirectoryExists(File directory) {
if (!directory.exists()) {
if (!queryYesNoQuestion(DataTransferMessages.DataTransfer_createTargetDirectory)) {
return false;
}
if (!directory.mkdirs()) {
displayErrorDialog(DataTransferMessages.DataTransfer_directoryCreationError);
giveFocusToDestination();
return false;
}
}
return true;
}
/**
* 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(destinationEmptyMessage());
return false;
}
String conflictingContainer = getConflictingContainerNameFor(destinationValue);
if (conflictingContainer == null) {
// no error message, but warning may exists
String threatenedContainer = getOverlappingProjectName(destinationValue);
if (threatenedContainer == null)
setMessage(null);
else
setMessage(NLS.bind(DataTransferMessages.FileExport_damageWarning, threatenedContainer), WARNING);
} else {
setErrorMessage(NLS.bind(DataTransferMessages.FileExport_conflictingContainer, conflictingContainer));
giveFocusToDestination();
return false;
}
return true;
}
/**
* Returns a boolean indicating whether the passed File handle is is valid and available for use.
*/
protected boolean ensureTargetFileIsValid(File targetFile) {
if (targetFile.exists() && targetFile.isDirectory()) {
displayErrorDialog(DataTransferMessages.ZipExport_mustBeFile);
giveFocusToDestination();
return false;
}
if (targetFile.exists()) {
if (targetFile.canWrite()) {
if (!queryYesNoQuestion(DataTransferMessages.ZipExport_alreadyExists)) {
return false;
}
} else {
displayErrorDialog(DataTransferMessages.ZipExport_alreadyExistsError);
giveFocusToDestination();
return false;
}
}
return true;
}
/**
* Open an appropriate destination browser so that the user can specify a source to import from
*/
protected void handleDestinationBrowseButtonPressed() {
FileDialog dialog = new FileDialog(getContainer().getShell(), SWT.SAVE | SWT.SHEET);
dialog.setFilterExtensions(new String[] { "*.hszip", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
dialog.setText(DataTransferMessages.ArchiveExport_selectDestinationTitle);
String currentSourceString = getDestinationValue();
int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator);
if (lastSeparatorIndex != -1) {
dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex));
}
String selectedFileName = dialog.open();
if (selectedFileName != null) {
setErrorMessage(null);
setDestinationValue(selectedFileName);
if (getWhiteCheckedResources().size() > 0) {
setDescription(null);
}
}
}
/**
* Constructor for ExternalProjectImportWizard.
*
* @param initialPath Default path for wizard to import
* @since 3.5
*/
public ImportProjectWizard(String initialPath)
{
super();
this.initialPath = initialPath;
setWindowTitle(DataTransferMessages.DataTransfer_importTitle);
setNeedsProgressMonitor(true);
IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault()
.getDialogSettings();
IDialogSettings wizardSettings = workbenchSettings
.getSection(IMPORT_PROJECT_SECTION);
if (wizardSettings == null) {
wizardSettings = workbenchSettings
.addNewSection(IMPORT_PROJECT_SECTION);
}
setDialogSettings(wizardSettings);
}
@Override
public boolean closeArchive(){
try {
getZipFile().close();
} catch (IOException e) {
IDEWorkbenchPlugin.log(DataTransferMessages.ZipImport_couldNotClose
+ getZipFile(), e);
return false;
}
return true;
}
@Override
public boolean closeArchive() {
try {
fFile.close();
} catch (IOException e) {
Activator.getDefault().logError(DataTransferMessages.ZipImport_couldNotClose
+ fFile.getName(), e);
return false;
}
return true;
}
@Override
public boolean closeArchive(){
try {
getTarFile().close();
} catch (IOException e) {
IDEWorkbenchPlugin.log(DataTransferMessages.ZipImport_couldNotClose
+ getTarFile().getName(), e);
return false;
}
return true;
}
/**
* Gets the label to be used when rendering this project record in the UI.
*
* @return String the label
* @since 3.4
*/
public String getProjectLabel() {
final String path =
projectSystemFile == null ? structureProvider.getLabel(parent) : projectSystemFile.getParent();
return NLS.bind(DataTransferMessages.WizardProjectsImportPage_projectLabel, projectName, path);
}
private void updateProjectsStatus() {
projectsList.refresh(true);
final ProjectRecord[] projects = getProjectRecords();
boolean displayConflictWarning = false;
boolean displayInvalidWarning = false;
for (final ProjectRecord project : projects) {
if (project.hasConflicts || project.isInvalid) {
projectsList.setGrayed(project, true);
displayConflictWarning |= project.hasConflicts;
displayInvalidWarning |= project.isInvalid;
} else {
projectsList.setChecked(project, true);
}
}
if (displayConflictWarning && displayInvalidWarning) {
setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspaceAndInvalid, WARNING);
} else if (displayConflictWarning) {
setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
} else if (displayInvalidWarning) {
setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInvalid, WARNING);
} else {
setMessage("Select a directory or an archive to search for existing GAMA projects.");
}
setPageComplete(projectsList.getCheckedElements().length > 0);
if (selectedProjects.length == 0) {
setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
}
}
/**
* The browse button has been selected. Select the location.
*/
protected void handleLocationDirectoryButtonPressed() {
final DirectoryDialog dialog = new DirectoryDialog(directoryPathField.getShell(), SWT.SHEET);
dialog.setMessage(DataTransferMessages.WizardProjectsImportPage_SelectDialogTitle);
String dirName = directoryPathField.getText().trim();
if (dirName.length() == 0) {
dirName = previouslyBrowsedDirectory;
}
if (dirName.length() == 0) {
dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
} else {
final File path = new File(dirName);
if (path.exists()) {
dialog.setFilterPath(new Path(dirName).toOSString());
}
}
final String selectedDirectory = dialog.open();
if (selectedDirectory != null) {
previouslyBrowsedDirectory = selectedDirectory;
directoryPathField.setText(previouslyBrowsedDirectory);
updateProjectsList(selectedDirectory);
}
}
/**
* The browse button has been selected. Select the location.
*/
protected void handleLocationArchiveButtonPressed() {
final FileDialog dialog = new FileDialog(archivePathField.getShell(), SWT.SHEET);
dialog.setFilterExtensions(FILE_IMPORT_MASK);
dialog.setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);
String fileName = archivePathField.getText().trim();
if (fileName.length() == 0) {
fileName = previouslyBrowsedArchive;
}
if (fileName.length() == 0) {
dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
} else {
final File path = new File(fileName).getParentFile();
if (path != null && path.exists()) {
dialog.setFilterPath(path.toString());
}
}
final String selectedArchive = dialog.open();
if (selectedArchive != null) {
previouslyBrowsedArchive = selectedArchive;
archivePathField.setText(previouslyBrowsedArchive);
updateProjectsList(selectedArchive);
}
}
/**
* The browse button has been selected. Select the location.
*/
protected void handleLocationDirectoryButtonPressed()
{
DirectoryDialog dialog = new DirectoryDialog(directoryPathField.getShell());
dialog.setMessage(DataTransferMessages.WizardProjectsImportPage_SelectDialogTitle);
String dirName = directoryPathField.getText().trim();
if (dirName.length() == 0)
{
dirName = previouslyBrowsedDirectory;
}
if (dirName.length() == 0)
{
dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getLocation().toOSString());
}
else
{
File path = new File(dirName);
if (path.exists())
{
dialog.setFilterPath(new Path(dirName).toOSString());
}
}
String selectedDirectory = dialog.open();
if (selectedDirectory != null)
{
previouslyBrowsedDirectory = selectedDirectory;
directoryPathField.setText(previouslyBrowsedDirectory);
}
setProjectName();
setPageComplete(directoryPathField.getText() != null);
}
/**
* Create the export destination specification widgets
* @param parent
* org.eclipse.swt.widgets.Composite
*/
protected void createDestinationGroup(Composite parent) {
Font font = parent.getFont();
// destination specification group
Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
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(getDestinationLabel());
destinationLabel.setFont(font);
// destination name entry field
destinationNameField = new Text(destinationSelectionGroup, SWT.BORDER);
destinationNameField.addListener(SWT.Modify, this);
destinationNameField.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
destinationNameField.setLayoutData(data);
destinationNameField.setFont(font);
// destination browse button
destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
destinationBrowseButton.addListener(SWT.Selection, this);
destinationBrowseButton.setFont(font);
setButtonLayoutData(destinationBrowseButton);
new Label(parent, SWT.NONE); // vertical spacer
}
/**
* Create the button for checking if we should ask if we are going to overwrite existing files.
* @param optionsGroup
* @param font
*/
protected void createOverwriteExisting(Group optionsGroup, Font font) {
// overwrite... checkbox
overwriteExistingFilesCheckbox = new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
overwriteExistingFilesCheckbox.setText(DataTransferMessages.ExportFile_overwriteExisting);
overwriteExistingFilesCheckbox.setFont(font);
}
/**
* If the target for export does not exist then attempt to create it. Answer a boolean indicating whether the target
* exists (ie.- if it either pre-existed or this method was able to create it)
* @return boolean
*/
protected boolean ensureTargetIsValid(File targetDirectory) {
if (targetDirectory.exists() && !targetDirectory.isDirectory()) {
displayErrorDialog(DataTransferMessages.FileExport_directoryExists);
giveFocusToDestination();
return false;
}
return ensureDirectoryExists(targetDirectory);
}
protected boolean validateSourceGroup() {
// there must be some resources selected for Export
boolean isValid = true;
List resourcesToExport = getWhiteCheckedResources();
if (resourcesToExport.size() == 0) {
setErrorMessage(DataTransferMessages.FileExport_noneSelected);
isValid = false;
} else if (getDestinationValue() != null && !getDestinationValue().equals("")) {
setDescription("");
} else {
setErrorMessage(null);
}
return super.validateSourceGroup() && isValid;
}
/**
* Returns the status of the operation. If there were any errors, the result is a status object containing
* individual status objects for each error. If there were no errors, the result is a status object with error code
* <code>OK</code>.
* @return the status
*/
public IStatus getStatus() {
IStatus[] errors = new IStatus[errorTable.size()];
errorTable.toArray(errors);
return new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.OK, errors,
DataTransferMessages.FileSystemExportOperation_problemsExporting, null);
}
/**
* Gets the label to be used when rendering this project record in the
* UI.
*
* @return String the label
* @since 3.4
*/
public String getProjectLabel() {
if (description == null)
return projectName;
String path = projectSystemFile == null ? structureProvider
.getLabel(parent) : projectSystemFile
.getParent();
return NLS.bind(
DataTransferMessages.WizardProjectsImportPage_projectLabel,
projectName, path);
}
/**
* More (many more) parameters.
*
* @param pageName
* @param initialPath
* @param currentSelection
* @since 3.5
*/
public ImportProjectWizardPage(String pageName,String initialPath,
IStructuredSelection currentSelection) {
super(pageName);
this.initialPath = initialPath;
this.currentSelection = currentSelection;
setPageComplete(false);
setTitle(DataTransferMessages.WizardProjectsImportPage_ImportProjectsTitle);
setDescription(Messages.getString("wizard.ImportProjectWizardPage.desc"));
setImageDescriptor(Activator.getImageDescriptor("images/importProject_logo.png"));
}
/**
* The browse button has been selected. Select the location.
*/
protected void handleLocationArchiveButtonPressed() {
FileDialog dialog = new FileDialog(archivePathField.getShell(), SWT.SHEET);
dialog.setFilterExtensions(FILE_IMPORT_MASK);
dialog
.setText(DataTransferMessages.WizardProjectsImportPage_SelectArchiveDialogTitle);
String fileName = archivePathField.getText().trim();
if (fileName.length() == 0) {
fileName = previouslyBrowsedArchive;
}
if (fileName.length() == 0) {
dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace()
.getRoot().getLocation().toOSString());
} else {
File path = new File(fileName).getParentFile();
if (path != null && path.exists()) {
dialog.setFilterPath(path.toString());
}
}
String selectedArchive = dialog.open();
if (selectedArchive != null) {
previouslyBrowsedArchive = selectedArchive;
archivePathField.setText(previouslyBrowsedArchive);
updateProjectsList(selectedArchive);
}
}
@SuppressWarnings("restriction")
protected ImportProjectWizardPage2(String pageName, String initialPath, IStructuredSelection currentSelection) {
super(pageName);
setTitle(DataTransferMessages.DataTransfer_importTitle);
initData();
}
@Override
protected void createDestinationGroup(Composite parent) {
Font font = parent.getFont();
// destination specification group
Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
destinationSelectionGroup.setLayout(layout);
destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
destinationSelectionGroup.setFont(font);
destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
destinationLabel.setText(getDestinationLabel());
destinationLabel.setFont(font);
// destination name entry field
destinationNameField = new Combo(destinationSelectionGroup, SWT.SINGLE | SWT.BORDER);
destinationNameField.addListener(SWT.Modify, this);
destinationNameField.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
destinationNameField.setLayoutData(data);
destinationNameField.setFont(font);
BidiUtils.applyBidiProcessing(destinationNameField, "file"); //$NON-NLS-1$
// destination browse button
destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
destinationBrowseButton.addListener(SWT.Selection, this);
destinationBrowseButton.setFont(font);
setButtonLayoutData(destinationBrowseButton);
new Label(parent, SWT.NONE); // vertical spacer
}
/**
* Create the export destination specification widgets
* @param parent
* org.eclipse.swt.widgets.Composite
*/
protected void createDestinationGroup(Composite parent) {
Font font = parent.getFont();
// destination specification group
Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
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(getDestinationLabel());
destinationLabel.setFont(font);
// destination name entry field
destinationNameField = new Text(destinationSelectionGroup, SWT.BORDER);
destinationNameField.addListener(SWT.Modify, this);
destinationNameField.addListener(SWT.Selection, this);
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
destinationNameField.setLayoutData(data);
destinationNameField.setFont(font);
// destination browse button
destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
destinationBrowseButton.addListener(SWT.Selection, this);
destinationBrowseButton.setFont(font);
setButtonLayoutData(destinationBrowseButton);
new Label(parent, SWT.NONE); // vertical spacer
}