Java Code Examples for org.eclipse.core.resources.IContainer#isVirtual()

The following examples show how to use org.eclipse.core.resources.IContainer#isVirtual() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectExplorerDropAdapterAssistant.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Performs a resource copy.
 * Cloned from ResourceDropAdapterAssistant to support linked resources (bug 319405).
 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter,
		Shell shell, IResource[] sources) {
	IContainer target = getDestination(dropAdapter.getCurrentTarget());
	if (target == null) {
		return Status.CANCEL_STATUS;
	}
	
	boolean shouldLinkAutomatically = false;
	if (target.isVirtual()) {
		shouldLinkAutomatically = true;
		for (int i = 0; i < sources.length; i++) {
			if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) {
				// If the source is a folder, but the location is null (a
				// broken link, for example),
				// we still generate a link automatically (the best option).
				shouldLinkAutomatically = false;
				break;
			}
		}
	}

	CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
	// if the target is a virtual folder and all sources are files, then
	// automatically create links
	if (shouldLinkAutomatically) {
		operation.setCreateLinks(true);
		operation.copyResources(sources, target);
	} else {
		boolean allSourceAreLinksOrVirtualFolders = true;
		for (int i = 0; i < sources.length; i++) {
			if (!sources[i].isVirtual() && !sources[i].isLinked()) {
				allSourceAreLinksOrVirtualFolders = false;
				break;
			}
		}
		// if all sources are either links or groups, copy then normally,
		// don't show the dialog
		if (!allSourceAreLinksOrVirtualFolders) {
			ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
			dialog.setResource(target);
			if (dialog.open() == Window.OK) {
				if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
					operation.setVirtualFolders(true);
				if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
					operation.setCreateLinks(true);
				if (dialog.getVariable() != null)
					operation.setRelativeVariable(dialog.getVariable());
				operation.copyResources(sources, target);
			} else
				return Status.CANCEL_STATUS;
		} else
			operation.copyResources(sources, target);
	}

	return Status.OK_STATUS;
}
 
Example 2
Source File: ImportTraceWizardPage.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean validateSourceGroup() {

    File source = getSourceFile();
    if (source == null) {
        setMessage(Messages.ImportTraceWizard_SelectTraceSourceEmpty);
        setErrorMessage(null);
        return false;
    }

    if (sourceConflictsWithDestination(new Path(source.getPath()))) {
        setMessage(null);
        setErrorMessage(getSourceConflictMessage());
        return false;
    }

    if (!isImportFromDirectory() && !ArchiveUtil.ensureTarSourceIsValid(source.getAbsolutePath()) && !ArchiveUtil.ensureZipSourceIsValid(source.getAbsolutePath())
            && !ArchiveUtil.ensureGzipSourceIsValid(source.getAbsolutePath())) {
        setMessage(null);
        setErrorMessage(Messages.ImportTraceWizard_BadArchiveFormat);
        return false;
    }

    if (fSelectionGroup.getCheckedElementCount() == 0) {
        setMessage(null);
        setErrorMessage(Messages.ImportTraceWizard_SelectTraceNoneSelected);
        return false;
    }

    IContainer container = getSpecifiedContainer();
    if (container != null && container.isVirtual()) {
        if (Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, ResourcesPlugin.PREF_DISABLE_LINKING, false, null)) {
            setMessage(null);
            setErrorMessage(Messages.ImportTraceWizard_CannotImportFilesUnderAVirtualFolder);
            return false;
        }
        if (fCreateLinksInWorkspaceButton == null || !fCreateLinksInWorkspaceButton.getSelection()) {
            setMessage(null);
            setErrorMessage(Messages.ImportTraceWizard_HaveToCreateLinksUnderAVirtualFolder);
            return false;
        }
    }
    setErrorMessage(null);
    return true;
}
 
Example 3
Source File: ResourceDropAdapterAssistant.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * Performs a resource copy
	 */
	private IStatus performResourceCopy(CommonDropAdapter dropAdapter,
			Shell shell, IResource[] sources) {
		MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1,
				WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
		mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(),
				dropAdapter.getCurrentOperation()));

		IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());

		boolean shouldLinkAutomatically = false;
		if (target.isVirtual()) {
			shouldLinkAutomatically = true;
			for (int i = 0; i < sources.length; i++) {
				if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) {
					// If the source is a folder, but the location is null (a
					// broken link, for example),
					// we still generate a link automatically (the best option).
					shouldLinkAutomatically = false;
					break;
				}
			}
		}

		CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
		// if the target is a virtual folder and all sources are files, then
		// automatically create links
		if (shouldLinkAutomatically) {
			operation.setCreateLinks(true);
			operation.copyResources(sources, target);
		} else {
//			boolean allSourceAreLinksOrVirtualFolders = true;
//			for (int i = 0; i < sources.length; i++) {
//				if (!sources[i].isVirtual() && !sources[i].isLinked()) {
//					allSourceAreLinksOrVirtualFolders = false;
//					break;
//				}
//			}
//			// if all sources are either links or groups, copy then normally,
//			// don't show the dialog
//			if (!allSourceAreLinksOrVirtualFolders) {
//				IPreferenceStore store= IDEWorkbenchPlugin.getDefault().getPreferenceStore();
//				String dndPreference= store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
//
//				if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
//					ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
//					dialog.setResource(target);
//					if (dialog.open() == Window.OK) {
//						if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
//							operation.setVirtualFolders(true);
//						if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
//							operation.setCreateLinks(true);
//						if (dialog.getVariable() != null)
//							operation.setRelativeVariable(dialog.getVariable());
//						operation.copyResources(sources, target);
//					} else
//						return problems;
//				}
//				else
//					operation.copyResources(sources, target);
//			} else
				operation.copyResources(sources, target);
		}

		return problems;
	}
 
Example 4
Source File: ResourceDropAdapterAssistant.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
	 * Performs a resource copy
	 */
	private IStatus performResourceCopy(CommonDropAdapter dropAdapter,
			Shell shell, IResource[] sources) {
		MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1,
				WorkbenchNavigatorMessages.resources_ResourceDropAdapterAssistant_problemsMoving, null);
		mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(),
				dropAdapter.getCurrentOperation()));

		IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());

		boolean shouldLinkAutomatically = false;
		if (target.isVirtual()) {
			shouldLinkAutomatically = true;
			for (int i = 0; i < sources.length; i++) {
				if ((sources[i].getType() != IResource.FILE) && (sources[i].getLocation() != null)) {
					// If the source is a folder, but the location is null (a
					// broken link, for example),
					// we still generate a link automatically (the best option).
					shouldLinkAutomatically = false;
					break;
				}
			}
		}

		CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
		// if the target is a virtual folder and all sources are files, then
		// automatically create links
		if (shouldLinkAutomatically) {
			operation.setCreateLinks(true);
			operation.copyResources(sources, target);
		} else {
//			boolean allSourceAreLinksOrVirtualFolders = true;
//			for (int i = 0; i < sources.length; i++) {
//				if (!sources[i].isVirtual() && !sources[i].isLinked()) {
//					allSourceAreLinksOrVirtualFolders = false;
//					break;
//				}
//			}
//			// if all sources are either links or groups, copy then normally,
//			// don't show the dialog
//			if (!allSourceAreLinksOrVirtualFolders) {
//				IPreferenceStore store= IDEWorkbenchPlugin.getDefault().getPreferenceStore();
//				String dndPreference= store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
//
//				if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
//					ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
//					dialog.setResource(target);
//					if (dialog.open() == Window.OK) {
//						if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
//							operation.setVirtualFolders(true);
//						if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
//							operation.setCreateLinks(true);
//						if (dialog.getVariable() != null)
//							operation.setRelativeVariable(dialog.getVariable());
//						operation.copyResources(sources, target);
//					} else
//						return problems;
//				}
//				else
//					operation.copyResources(sources, target);
//			} else
				operation.copyResources(sources, target);
		}

		return problems;
	}