diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 7b11447d88a..a77eee084fe 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,11 @@ +2004-03-26 David Inglis + + WORKING PROGRESS new C Path entry UI - Project property page to add/remove/reorder + src paths, output paths, project references and export/order. + UI not enabled yet + no many file to list here..... + + 2004-03-25 Hoda Amer Added the timeout capability for content assist. Added a preference for the user to set up the timeout limit for content assist diff --git a/core/org.eclipse.cdt.ui/icons/full/obj16/cp_order_obj.gif b/core/org.eclipse.cdt.ui/icons/full/obj16/cp_order_obj.gif new file mode 100644 index 00000000000..98ec3b34bad Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/full/obj16/cp_order_obj.gif differ diff --git a/core/org.eclipse.cdt.ui/icons/full/obj16/exclusion_filter_attrib.gif b/core/org.eclipse.cdt.ui/icons/full/obj16/exclusion_filter_attrib.gif new file mode 100644 index 00000000000..3d83fd6ca04 Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/full/obj16/exclusion_filter_attrib.gif differ diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index f4226fa6b93..270e9a9448a 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -550,5 +550,21 @@ - + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java index b6edae88a21..1ed598baf62 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java @@ -20,7 +20,7 @@ import org.eclipse.swt.graphics.Image; public class CPluginImages { // The plugin registry - private static ImageRegistry imageRegistry = new ImageRegistry(); + private static ImageRegistry imageRegistry = new ImageRegistry(CUIPlugin.getStandardDisplay()); // Subdirectory (under the package containing this class) where 16 color images are private static URL fgIconBaseURL; @@ -55,6 +55,7 @@ public class CPluginImages { public static final String IMG_OBJS_FUNCTION= NAME_PREFIX + "function_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_PUBLIC_METHOD= NAME_PREFIX + "method_public_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_PROTECTED_METHOD= NAME_PREFIX + "method_protected_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_PRIVATE_METHOD= NAME_PREFIX + "method_private_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_PUBLIC_FIELD= NAME_PREFIX + "field_public_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_PROTECTED_FIELD= NAME_PREFIX + "field_protected_obj.gif"; //$NON-NLS-1$ @@ -67,7 +68,7 @@ public class CPluginImages { public static final String IMG_OBJS_TUNIT_HEADER= NAME_PREFIX + "h_file_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_TUNIT_ASM= NAME_PREFIX + "s_file_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_TUNIT_RESOURCE= NAME_PREFIX + "c_resource_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJS_SOURCE_ROOT= NAME_PREFIX + "cfolder_obj.gif"; // $NON-NLS-1$ + public static final String IMG_OBJS_SOURCE_ROOT= NAME_PREFIX + "cfolder_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$ public static final String IMG_OBJS_ARCHIVE= NAME_PREFIX + "ar_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_BINARY= NAME_PREFIX + "bin_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SHLIB= NAME_PREFIX + "shlib_obj.gif"; //$NON-NLS-1$ @@ -76,7 +77,10 @@ public class CPluginImages { public static final String IMG_OBJS_CORE= NAME_PREFIX + "core_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_CONTAINER= NAME_PREFIX + "container_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_LIBRARY= NAME_PREFIX + "lib_obj.gif"; //$NON-NLS-1$ - + public static final String IMG_OBJS_ORDER= NAME_PREFIX + "cp_order_obj.gif"; //$NON-NLS-1$ + public static final String IMG_OBJS_EXCLUDSION_FILTER_ATTRIB= NAME_PREFIX + "exclusion_filter_attrib.gif"; //$NON-NLS-1$ + + public static final String IMG_OBJS_ARCHIVE_WSRC= NAME_PREFIX + "ar_src_obj.gif"; //$NON-NLS-1$ // Breakpoint images public static final String IMG_OBJS_BREAKPOINT = NAME_PREFIX + "breakpoint.gif"; //$NON-NLS-1$ @@ -112,6 +116,7 @@ public class CPluginImages { public static final ImageDescriptor DESC_OBJS_TUNIT_RESOURCE= createManaged(T_OBJ, IMG_OBJS_TUNIT_RESOURCE); public static final ImageDescriptor DESC_OBJS_SOURCE_ROOT= createManaged(T_OBJ, IMG_OBJS_SOURCE_ROOT); public static final ImageDescriptor DESC_OBJS_ARCHIVE= createManaged(T_OBJ, IMG_OBJS_ARCHIVE); + public static final ImageDescriptor DESC_OBJS_ARCHIVE_WSRC= createManaged(T_OBJ, IMG_OBJS_ARCHIVE); public static final ImageDescriptor DESC_OBJS_BINARY= createManaged(T_OBJ, IMG_OBJS_BINARY); public static final ImageDescriptor DESC_OBJS_SHLIB= createManaged(T_OBJ, IMG_OBJS_SHLIB); public static final ImageDescriptor DESC_OBJS_CEXEC= createManaged(T_OBJ, IMG_OBJS_CEXEC); @@ -119,7 +124,9 @@ public class CPluginImages { public static final ImageDescriptor DESC_OBJS_CORE= createManaged(T_OBJ, IMG_OBJS_CORE); public static final ImageDescriptor DESC_OBJS_CONTAINER= createManaged(T_OBJ, IMG_OBJS_CONTAINER); public static final ImageDescriptor DESC_OBJS_LIBRARY= createManaged(T_OBJ, IMG_OBJS_LIBRARY); - + public static final ImageDescriptor DESC_OBJS_ORDER= createManaged(T_OBJ, IMG_OBJS_ORDER); + public static final ImageDescriptor DESC_OBJS_EXCLUSION_FILTER_ATTRIB = createManaged(T_OBJ, IMG_OBJS_EXCLUDSION_FILTER_ATTRIB); + // Breakpoint image descriptors public static final ImageDescriptor DESC_OBJS_BREAKPOINT = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT ); public static final ImageDescriptor DESC_OBJS_BREAKPOINT_DISABLED = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT_DISABLED ); @@ -155,15 +162,13 @@ public class CPluginImages { public static final ImageDescriptor DESC_WIZABAN_NEW_PROJ= create(T_WIZBAN, "newcprj_wiz.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZBAN_NEWCLASS= create(T_WIZBAN, "newclass_wiz.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_WIZABAN_C_APP= create(T_WIZBAN, "c_app_wiz.gif"); //$NON-NLS-1$ - public static final String IMG_OBJS_PROJECT = NAME_PREFIX + "prj_obj.gif"; //$NON-NLS-1$ - public static final ImageDescriptor DESC_PROJECT= createManaged(T_WIZBAN, IMG_OBJS_PROJECT); public static final ImageDescriptor DESC_TOOL_NEWCLASS= create(T_TOOL, "newclass_wiz.gif"); //$NON-NLS-1$ // For the build image public static final String IMG_OBJS_BUILD= NAME_PREFIX + "build_menu.gif"; //$NON-NLS-1$ public static final ImageDescriptor DESC_BUILD_MENU = createManaged(T_OBJ, IMG_OBJS_BUILD); - + //for search public static final String IMG_OBJS_SEARCH_REF = NAME_PREFIX + "search_ref_obj.gif"; //$NON-NLS-1$ public static final String IMG_OBJS_SEARCH_DECL = NAME_PREFIX + "search_decl_obj.gif"; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/StatusInfo.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/StatusInfo.java index 8e531198b71..356d3f66839 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/StatusInfo.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/StatusInfo.java @@ -18,7 +18,25 @@ public class StatusInfo implements IStatus { private String fStatusMessage; private int fSeverity; - + + /** + * Creates a status set to OK (no message) + */ + public StatusInfo() { + this(OK, null); + } + + /** + * Creates a status . + * @param severity The status severity: ERROR, WARNING, INFO and OK. + * @param message The message of the status. Applies only for ERROR, + * WARNING and INFO. + */ + public StatusInfo(int severity, String message) { + fStatusMessage= message; + fSeverity= severity; + } + /** * @see IStatus#getChildren() */ @@ -95,8 +113,4 @@ public class StatusInfo implements IStatus { fStatusMessage= warningMessage; fSeverity= IStatus.WARNING; } - public StatusInfo() { - fStatusMessage= null; - fSeverity= OK; - } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java new file mode 100644 index 00000000000..bac8a6dd05d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ArchiveFileFilter.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +/** + * Viewer filter for archive selection dialogs. Archives are files with file + * extension '.so', '.dll' and '.a'. The filter is not case sensitive. + */ +public class ArchiveFileFilter extends ViewerFilter { + + private static final String[] fgArchiveExtensions = { ".so", ".a", ".dll"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private List fExcludes; + private boolean fRecursive; + + /** + * @param excludedFiles + * Excluded files will not pass the filter. null is + * allowed if no files should be excluded. + * @param recusive + * Folders are only shown if, searched recursivly, contain an archive + */ + public ArchiveFileFilter(IFile[] excludedFiles, boolean recusive) { + if (excludedFiles != null) { + fExcludes = Arrays.asList(excludedFiles); + } else { + fExcludes = null; + } + fRecursive = recusive; + } + + /* + * @see ViewerFilter#select + */ + public boolean select(Viewer viewer, Object parent, Object element) { + if (element instanceof IFile) { + if (fExcludes != null && fExcludes.contains(element)) { + return false; + } + return isArchivePath(((IFile) element).getFullPath()); + } else if (element instanceof IContainer) { // IProject, IFolder + if (!fRecursive) { + return true; + } + try { + IResource[] resources = ((IContainer) element).members(); + for (int i = 0; i < resources.length; i++) { + // recursive! Only show containers that contain an archive + if (select(viewer, parent, resources[i])) { + return true; + } + } + } catch (CoreException e) { + CUIPlugin.getDefault().log(e.getStatus()); + } + } + return false; + } + + public static boolean isArchivePath(IPath path) { + String ext = path.getFileExtension(); + if (ext != null && ext.length() != 0) { + return isArchiveFileExtension(ext); + } + return false; + } + + public static boolean isArchiveFileExtension(String ext) { + for (int i = 0; i < fgArchiveExtensions.length; i++) { + if (ext.equalsIgnoreCase(fgArchiveExtensions[i])) { + return true; + } + } + return false; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java new file mode 100644 index 00000000000..56013f3c80f --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElement.java @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; + +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.core.model.IIncludeEntry; +import org.eclipse.cdt.core.model.ILibraryEntry; +import org.eclipse.cdt.core.model.IMacroEntry; +import org.eclipse.cdt.core.model.IOutputEntry; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.IPathEntryContainer; +import org.eclipse.cdt.core.model.ISourceEntry; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + +public class CPListElement { + + public static final String SOURCEATTACHMENT = "sourcepath"; //$NON-NLS-1$ + public static final String SOURCEATTACHMENTROOT = "rootpath"; //$NON-NLS-1$ + public static final String EXCLUSION = "exclusion"; //$NON-NLS-1$ + public static final String INCLUDE = "includepath"; //$NON-NLS-1$ + public static final String DEFINE = "define"; //$NON-NLS-1$ + + private ICProject fProject; + + private int fEntryKind; + private IPath fPath; + private IResource fResource; + private boolean fIsExported; + private boolean fIsMissing; + + private CPListElement fParentContainer; + + private IPathEntry fCachedEntry; + private ArrayList fChildren; + + public CPListElement(ICProject project, int entryKind, IPath path, IResource res) { + fProject = project; + + fEntryKind = entryKind; + fPath = path; + fChildren = new ArrayList(); + fResource = res; + fIsExported = false; + + fIsMissing = false; + fCachedEntry = null; + fParentContainer = null; + + switch (entryKind) { + case IPathEntry.CDT_OUTPUT: + createAttributeElement(EXCLUSION, new Path[0]); + break; + case IPathEntry.CDT_SOURCE: + createAttributeElement(EXCLUSION, new Path[0]); + break; + case IPathEntry.CDT_LIBRARY: + createAttributeElement(SOURCEATTACHMENT, null); + break; + case IPathEntry.CDT_PROJECT: + case IPathEntry.CDT_INCLUDE: + createAttributeElement(INCLUDE, null); + break; + case IPathEntry.CDT_MACRO: + createAttributeElement(DEFINE, null); + break; + case IPathEntry.CDT_CONTAINER: + try { + IPathEntryContainer container = CoreModel.getDefault().getPathEntryContainer(fPath, fProject); + if (container != null) { + IPathEntry[] entries = container.getPathEntries(); + for (int i = 0; i < entries.length; i++) { + CPListElement curr = createFromExisting(entries[i], fProject); + curr.setParentContainer(this); + fChildren.add(curr); + } + } + } catch (CModelException e) { + } + break; + default: + } + } + + public IPathEntry getPathEntry() { + if (fCachedEntry == null) { + fCachedEntry = newPathEntry(); + } + return fCachedEntry; + } + + private IPathEntry newPathEntry() { + IPath[] exclusionPattern; + switch (fEntryKind) { + case IPathEntry.CDT_OUTPUT: + exclusionPattern = (IPath[]) getAttribute(EXCLUSION); + return CoreModel.newOutputEntry(fPath, exclusionPattern); + case IPathEntry.CDT_SOURCE: + exclusionPattern = (IPath[]) getAttribute(EXCLUSION); + return CoreModel.newSourceEntry(fPath, exclusionPattern); + case IPathEntry.CDT_LIBRARY: + IPath attach = (IPath) getAttribute(SOURCEATTACHMENT); + return CoreModel.newLibraryEntry(fPath, attach, null, null, isExported()); + case IPathEntry.CDT_PROJECT: + return CoreModel.newProjectEntry(fPath, isExported()); + case IPathEntry.CDT_CONTAINER: + return CoreModel.newContainerEntry(fPath, isExported()); + case IPathEntry.CDT_INCLUDE: + exclusionPattern = (IPath[]) getAttribute(EXCLUSION); + return CoreModel.newIncludeEntry(fPath, (IPath) getAttribute(INCLUDE)); + case IPathEntry.CDT_MACRO: + exclusionPattern = (IPath[]) getAttribute(EXCLUSION); + return CoreModel.newMacroEntry(fPath, (String) getAttribute(DEFINE), null); + default: + return null; + } + } + + public static StringBuffer appendEncodePath(IPath path, StringBuffer buf) { + if (path != null) { + String str= path.toString(); + buf.append('[').append(str.length()).append(']').append(str); + } else { + buf.append('[').append(']'); + } + return buf; + } + + /** + * @return + */ + public StringBuffer appendEncodedSettings(StringBuffer buf) { + buf.append(fEntryKind).append(';'); + appendEncodePath(fPath, buf).append(';'); + buf.append(Boolean.valueOf(fIsExported)).append(';'); + switch (fEntryKind) { + case IPathEntry.CDT_OUTPUT: + case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_INCLUDE: + case IPathEntry.CDT_MACRO: + IPath[] exclusion= (IPath[]) getAttribute(EXCLUSION); + buf.append('[').append(exclusion.length).append(']'); + for (int i= 0; i < exclusion.length; i++) { + appendEncodePath(exclusion[i], buf).append(';'); + } + break; + case IPathEntry.CDT_LIBRARY: + IPath sourceAttach= (IPath) getAttribute(SOURCEATTACHMENT); + appendEncodePath(sourceAttach, buf).append(';'); + break; + default: + + } + return buf; + } + + /** + * Gets the path entry path. + * + * @see IPathEntry#getPath() + */ + public IPath getPath() { + return fPath; + } + + /** + * Gets the classpath entry kind. + * + * @see IPathEntry#getEntryKind() + */ + public int getEntryKind() { + return fEntryKind; + } + + /** + * Entries without resource are either non existing or a variable entry + * External jars do not have a resource + */ + public IResource getResource() { + return fResource; + } + + public CPListElementAttribute setAttribute(String key, Object value) { + CPListElementAttribute attribute = findAttributeElement(key); + if (attribute == null) { + return null; + } + attribute.setValue(value); + attributeChanged(key); + return attribute; + } + + private CPListElementAttribute findAttributeElement(String key) { + for (int i = 0; i < fChildren.size(); i++) { + Object curr = fChildren.get(i); + if (curr instanceof CPListElementAttribute) { + CPListElementAttribute elem = (CPListElementAttribute) curr; + if (key.equals(elem.getKey())) { + return elem; + } + } + } + return null; + } + + public Object getAttribute(String key) { + CPListElementAttribute attrib = findAttributeElement(key); + if (attrib != null) { + return attrib.getValue(); + } + return null; + } + + private void createAttributeElement(String key, Object value) { + fChildren.add(new CPListElementAttribute(this, key, value)); + } + + public Object[] getChildren() { + if (fEntryKind == IPathEntry.CDT_OUTPUT || fEntryKind == IPathEntry.CDT_SOURCE || fEntryKind == IPathEntry.CDT_INCLUDE || fEntryKind == IPathEntry.CDT_MACRO) { + + return new Object[] { findAttributeElement(EXCLUSION)}; + + } + return fChildren.toArray(); + } + + private void setParentContainer(CPListElement element) { + fParentContainer = element; + } + + public CPListElement getParentContainer() { + return fParentContainer; + } + + private void attributeChanged(String key) { + fCachedEntry = null; + } + + /* + * @see Object#equals(java.lang.Object) + */ + public boolean equals(Object other) { + if (other != null && other.getClass().equals(getClass())) { + CPListElement elem = (CPListElement) other; + return elem.fEntryKind == fEntryKind && elem.fPath.equals(fPath); + } + return false; + } + + /* + * @see Object#hashCode() + */ + public int hashCode() { + return fPath.hashCode() + fEntryKind; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + public String toString() { + return getPathEntry().toString(); + } + + /** + * Returns if a entry is missing. + * + * @return Returns a boolean + */ + public boolean isMissing() { + return fIsMissing; + } + + /** + * Sets the 'missing' state of the entry. + */ + public void setIsMissing(boolean isMissing) { + fIsMissing = isMissing; + } + + /** + * Returns if a entry is exported (only applies to libraries) + * + * @return Returns a boolean + */ + public boolean isExported() { + return fIsExported; + } + + /** + * Sets the export state of the entry. + */ + public void setExported(boolean isExported) { + if (isExported != fIsExported) { + fIsExported = isExported; + + attributeChanged(null); + } + } + + /** + * Gets the project. + * + * @return Returns a ICProject + */ + public ICProject getCProject() { + return fProject; + } + + public static CPListElement createFromExisting(IPathEntry curr, ICProject project) { + IPath path = curr.getPath(); + IWorkspaceRoot root = project.getProject().getWorkspace().getRoot(); + IPath sourceAttachment = null; + IPath[] exclusion = null; + // get the resource + IResource res = null; + boolean isMissing = false; + // URL javaDocLocation = null; + + switch (curr.getEntryKind()) { + case IPathEntry.CDT_CONTAINER: + res = null; + try { + isMissing = (CoreModel.getDefault().getPathEntryContainer(path, project) == null); + } catch (CModelException e) { + } + break; + case IPathEntry.CDT_LIBRARY: + res = root.findMember(path); + if (res == null) { + if (!ArchiveFileFilter.isArchivePath(path)) { + if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK() + && root.getProject(path.segment(0)).exists()) { + res = root.getFolder(path); + } + } + isMissing = !path.toFile().isFile(); // look for external + } + sourceAttachment = ((ILibraryEntry) curr).getSourceAttachmentPath(); + break; + case IPathEntry.CDT_SOURCE: + path = path.removeTrailingSeparator(); + res = root.findMember(path); + if (res == null) { + if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { + res = root.getFolder(path); + } + isMissing = true; + } + exclusion = ((ISourceEntry) curr).getExclusionPatterns(); + break; + case IPathEntry.CDT_OUTPUT: + path = path.removeTrailingSeparator(); + res = root.findMember(path); + if (res == null) { + if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { + res = root.getFolder(path); + } + isMissing = true; + } + exclusion = ((IOutputEntry) curr).getExclusionPatterns(); + break; + case IPathEntry.CDT_INCLUDE: + path = path.removeTrailingSeparator(); + res = root.findMember(path); + if (res == null) { + if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { + res = root.getFolder(path); + } + isMissing = !path.toFile().isFile(); // look for external + } + exclusion = ((IIncludeEntry) curr).getExclusionPatterns(); + break; + case IPathEntry.CDT_MACRO: + path = path.removeTrailingSeparator(); + res = root.findMember(path); + if (res == null) { + if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) { + res = root.getFolder(path); + } + isMissing = !path.toFile().isFile(); // look for external + } + exclusion = ((IMacroEntry) curr).getExclusionPatterns(); + break; + case IPathEntry.CDT_PROJECT: + res = root.findMember(path); + isMissing = (res == null); + break; + } + CPListElement elem = new CPListElement(project, curr.getEntryKind(), path, res); + elem.setAttribute(SOURCEATTACHMENT, sourceAttachment); + elem.setAttribute(EXCLUSION, exclusion); + elem.setExported(curr.isExported()); + + if (project.exists()) { + elem.setIsMissing(isMissing); + } + return elem; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementAttribute.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementAttribute.java new file mode 100644 index 00000000000..cf3f00e2130 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementAttribute.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +public class CPListElementAttribute { + + private CPListElement fParent; + private String fKey; + private Object fValue; + + public CPListElementAttribute(CPListElement parent, String key, Object value) { + fKey = key; + fValue = value; + fParent = parent; + } + + public CPListElement getParent() { + return fParent; + } + + /** + * Returns the key. + * + * @return String + */ + public String getKey() { + return fKey; + } + + /** + * Returns the value. + * + * @return Object + */ + public Object getValue() { + return fValue; + } + + /** + * Returns the value. + */ + public void setValue(Object value) { + fValue = value; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementSorter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementSorter.java new file mode 100644 index 00000000000..6164dd08a06 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListElementSorter.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.jface.viewers.ViewerSorter; + +public class CPListElementSorter extends ViewerSorter { + + private static final int SOURCE = 0; + private static final int PROJECT = 1; + private static final int LIBRARY = 2; + private static final int VARIABLE = 3; + private static final int CONTAINER = 4; + private static final int OTHER = 5; + + /* + * @see ViewerSorter#category(Object) + */ + public int category(Object obj) { + if (obj instanceof CPListElement) { + switch (((CPListElement) obj).getEntryKind()) { + case IPathEntry.CDT_LIBRARY: + return LIBRARY; + case IPathEntry.CDT_PROJECT: + return PROJECT; + case IPathEntry.CDT_SOURCE: + return SOURCE; + case IPathEntry.CDT_VARIABLE: + return VARIABLE; + case IPathEntry.CDT_CONTAINER: + return CONTAINER; + } + } + return OTHER; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListLabelProvider.java new file mode 100644 index 00000000000..c188afa9fdd --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPListLabelProvider.java @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.IPathEntryContainer; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; +import org.eclipse.cdt.ui.CElementImageDescriptor; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.ide.IDE; + +class CPListLabelProvider extends LabelProvider { + + private String fNewLabel, fClassLabel, fCreateLabel; + private ImageDescriptor fIncludeIcon, fMacroIcon, fLibWSrcIcon, fLibIcon, fExtLibIcon, fExtLibWSrcIcon; + private ImageDescriptor fFolderImage, fOutputImage, fProjectImage, fContainerImage; + + private ImageDescriptorRegistry fRegistry; + + public CPListLabelProvider() { + fNewLabel = CPathEntryMessages.getString("CPListLabelProvider.new"); //$NON-NLS-1$ + fClassLabel = CPathEntryMessages.getString("CPListLabelProvider.classcontainer"); //$NON-NLS-1$ + fCreateLabel = CPathEntryMessages.getString("CPListLabelProvider.willbecreated"); //$NON-NLS-1$ + fRegistry = CUIPlugin.getImageDescriptorRegistry(); + + fLibIcon = CPluginImages.DESC_OBJS_ARCHIVE; + fLibWSrcIcon = CPluginImages.DESC_OBJS_ARCHIVE_WSRC; + fIncludeIcon = CPluginImages.DESC_OBJS_INCLUDE; + fMacroIcon = CPluginImages.DESC_OBJS_MACRO; + fFolderImage = CPluginImages.DESC_OBJS_SOURCE_ROOT; + fOutputImage = CPluginImages.DESC_OBJS_CONTAINER; + fContainerImage = CPluginImages.DESC_OBJS_LIBRARY; + + IWorkbench workbench = CUIPlugin.getDefault().getWorkbench(); + + fProjectImage = workbench.getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT); + } + + public String getText(Object element) { + if (element instanceof CPListElement) { + return getCPListElementText((CPListElement) element); + } else if (element instanceof CPListElementAttribute) { + return getCPListElementAttributeText((CPListElementAttribute) element); + } + return super.getText(element); + } + + public String getCPListElementAttributeText(CPListElementAttribute attrib) { + String notAvailable = CPathEntryMessages.getString("CPListLabelProvider.none"); //$NON-NLS-1$ + StringBuffer buf = new StringBuffer(); + String key = attrib.getKey(); + if (key.equals(CPListElement.SOURCEATTACHMENT)) { + buf.append(CPathEntryMessages.getString("CPListLabelProvider.source_attachment.label")); //$NON-NLS-1$ + IPath path = (IPath) attrib.getValue(); + if (path != null && !path.isEmpty()) { + buf.append(getPathString(path, path.getDevice() != null)); + } else { + buf.append(notAvailable); + } + } else if (key.equals(CPListElement.SOURCEATTACHMENTROOT)) { + buf.append(CPathEntryMessages.getString("CPListLabelProvider.source_attachment_root.label")); //$NON-NLS-1$ + IPath path = (IPath) attrib.getValue(); + if (path != null && !path.isEmpty()) { + buf.append(path.toString()); + } else { + buf.append(notAvailable); + } + } + if (key.equals(CPListElement.EXCLUSION)) { + buf.append(CPathEntryMessages.getString("CPListLabelProvider.exclusion_filter.label")); //$NON-NLS-1$ + IPath[] patterns = (IPath[]) attrib.getValue(); + if (patterns != null && patterns.length > 0) { + for (int i = 0; i < patterns.length; i++) { + if (i > 0) { + buf.append(CPathEntryMessages.getString("CPListLabelProvider.exclusion_filter_separator")); //$NON-NLS-1$ + } + buf.append(patterns[i].toString()); + } + } else { + buf.append(notAvailable); + } + } + return buf.toString(); + } + + public String getCPListElementText(CPListElement cpentry) { + IPath path = cpentry.getPath(); + switch (cpentry.getEntryKind()) { + case IPathEntry.CDT_LIBRARY: + { + IResource resource = cpentry.getResource(); + if (resource instanceof IContainer) { + StringBuffer buf = new StringBuffer(path.makeRelative().toString()); + buf.append(' '); + buf.append(fClassLabel); + if (!resource.exists()) { + buf.append(' '); + if (cpentry.isMissing()) { + buf.append(fCreateLabel); + } else { + buf.append(fNewLabel); + } + } + return buf.toString(); + } else if (ArchiveFileFilter.isArchivePath(path)) { + return getPathString(path, resource == null); + } + // should not come here + return path.makeRelative().toString(); + } + case IPathEntry.CDT_PROJECT: + return path.lastSegment(); + case IPathEntry.CDT_CONTAINER: + try { + IPathEntryContainer container = CoreModel.getDefault().getPathEntryContainer(cpentry.getPath(), + cpentry.getCProject()); + if (container != null) { + return container.getDescription(); + } + } catch (CModelException e) { + } + return path.toString(); + case IPathEntry.CDT_SOURCE: + case IPathEntry.CDT_OUTPUT: + { + StringBuffer buf = new StringBuffer(path.makeRelative().toString()); + IResource resource = cpentry.getResource(); + if (resource != null && !resource.exists()) { + buf.append(' '); + if (cpentry.isMissing()) { + buf.append(fCreateLabel); + } else { + buf.append(fNewLabel); + } + } + return buf.toString(); + } + default: + // pass + } + return CPathEntryMessages.getString("CPListLabelProvider.unknown_element.label"); //$NON-NLS-1$ + } + + private String getPathString(IPath path, boolean isExternal) { + if (ArchiveFileFilter.isArchivePath(path)) { + IPath appendedPath = path.removeLastSegments(1); + String appended = isExternal ? appendedPath.toOSString() : appendedPath.makeRelative().toString(); + return CPathEntryMessages.getFormattedString("CPListLabelProvider.twopart", new String[] { path.lastSegment(), appended}); //$NON-NLS-1$ + } else { + return isExternal ? path.toOSString() : path.makeRelative().toString(); + } + } + + private ImageDescriptor getCPListElementBaseImage(CPListElement cpentry) { + switch (cpentry.getEntryKind()) { + case IPathEntry.CDT_OUTPUT: + if (cpentry.getPath().segmentCount() == 1) { + return fProjectImage; + } else { + return fOutputImage; + } + case IPathEntry.CDT_SOURCE: + if (cpentry.getPath().segmentCount() == 1) { + return fProjectImage; + } else { + return fFolderImage; + } + case IPathEntry.CDT_LIBRARY: + IResource res = cpentry.getResource(); + IPath path = (IPath) cpentry.getAttribute(CPListElement.SOURCEATTACHMENT); + if (res == null) { + if (path == null || path.isEmpty()) { + return fExtLibIcon; + } else { + return fExtLibWSrcIcon; + } + } else if (res instanceof IFile) { + if (path == null || path.isEmpty()) { + return fLibIcon; + } else { + return fLibWSrcIcon; + } + } else { + return fFolderImage; + } + case IPathEntry.CDT_PROJECT: + return fProjectImage; + case IPathEntry.CDT_CONTAINER: + return fContainerImage; + case IPathEntry.CDT_INCLUDE: + return fIncludeIcon; + case IPathEntry.CDT_MACRO: + return fMacroIcon; + default: + return null; + } + } + + private static final Point SMALL_SIZE = new Point(16, 16); + + public Image getImage(Object element) { + if (element instanceof CPListElement) { + CPListElement cpentry = (CPListElement) element; + ImageDescriptor imageDescriptor = getCPListElementBaseImage(cpentry); + if (imageDescriptor != null) { + if (cpentry.isMissing()) { + imageDescriptor = new CElementImageDescriptor(imageDescriptor, CElementImageDescriptor.WARNING, SMALL_SIZE); + } + return fRegistry.get(imageDescriptor); + } + } else if (element instanceof CPListElementAttribute) { + String key = ((CPListElementAttribute) element).getKey(); + if (key.equals(CPListElement.SOURCEATTACHMENT)) { +// return fRegistry.get(CPluginImages.DESC_OBJS_SOURCE_ATTACH_ATTRIB); + } else if (key.equals(CPListElement.EXCLUSION)) { + return CPluginImages.get(CPluginImages.IMG_OBJS_EXCLUDSION_FILTER_ATTRIB); + } else if (key.equals(CPListElement.INCLUDE)) { +// return fRegistry.get(CPluginImages.DESC_OBJS_INCLUDE_ATTRIB); + } else if (key.equals(CPListElement.DEFINE)) { +// return fRegistry.get(CPluginImages.DESC_OBJS_MACRO_ATTRIB); + } + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java new file mode 100644 index 00000000000..825483ae27c --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathBasePage.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.ui.dialogs.AbstractCOptionPage; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.resource.ImageDescriptor; + +public abstract class CPathBasePage extends AbstractCOptionPage { + + public abstract List getSelection(); + + public abstract void setSelection(List selection); + + public abstract boolean isEntryKind(int kind); + + public CPathBasePage(String title) { + super(title); + } + public CPathBasePage(String title, ImageDescriptor image) { + super(title, image); + } + + protected void filterAndSetSelection(List list) { + ArrayList res = new ArrayList(list.size()); + for (int i = list.size() - 1; i >= 0; i--) { + Object curr = list.get(i); + if (curr instanceof CPListElement) { + CPListElement elem = (CPListElement) curr; + if (elem.getParentContainer() == null && isEntryKind(elem.getEntryKind())) { + res.add(curr); + } + } + } + setSelection(res); + } + + protected void fixNestingConflicts(List newEntries, List existing, Set modifiedSourceEntries) { + for (int i = 0; i < newEntries.size(); i++) { + CPListElement curr = (CPListElement) newEntries.get(i); + addExclusionPatterns(curr, existing, modifiedSourceEntries); + } + } + + private void addExclusionPatterns(CPListElement newEntry, List existing, Set modifiedEntries) { + IPath entryPath = newEntry.getPath(); + for (int i = 0; i < existing.size(); i++) { + CPListElement curr = (CPListElement) existing.get(i); + if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) { + IPath currPath = curr.getPath(); + if (currPath.isPrefixOf(entryPath) && !currPath.equals(entryPath)) { + IPath[] exclusionFilters = (IPath[]) curr.getAttribute(CPListElement.EXCLUSION); + if (!CoreModelUtil.isExcludedPath(entryPath, exclusionFilters)) { + IPath pathToExclude = entryPath.removeFirstSegments(currPath.segmentCount()).addTrailingSeparator(); + IPath[] newExclusionFilters = new IPath[exclusionFilters.length + 1]; + System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length); + newExclusionFilters[exclusionFilters.length] = pathToExclude; + curr.setAttribute(CPListElement.EXCLUSION, newExclusionFilters); + modifiedEntries.add(curr); + } + } + } + } + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.java new file mode 100644 index 00000000000..783ec6a495a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2001 Rational Software Corp. 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: + * Rational Software - initial implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + + +public class CPathEntryMessages { + + private static final String RESOURCE_BUNDLE= CPathEntryMessages.class.getName(); + private static ResourceBundle fgResourceBundle; + static { + try { + fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); + } catch (MissingResourceException x) { + fgResourceBundle = null; + } + } + + private CPathEntryMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } catch (NullPointerException e) { + return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + */ + public static String getFormattedString(String key, Object arg) { + return MessageFormat.format(getString(key), new Object[] { arg }); + } + + /** + * Gets a string from the resource bundle and formats it with arguments + */ + public static String getFormattedString(String key, Object[] args) { + return MessageFormat.format(getString(key), args); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties new file mode 100644 index 00000000000..dd80fb047ce --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathEntryMessages.properties @@ -0,0 +1,198 @@ +############################################################################### +# Copyright (c) 2004 QNX Software Systems and others. All rights reserved. +# This program and the accompanying materials are made available under the +# terms of the Common Public License v1.0 which accompanies this distribution, +# and is available at http://www.eclipse.org/legal/cpl-v10.html +# +# Contributors: QNX Software Systems - initial API and implementation +############################################################################### + +CPathsPropertyPage.no_C_project.message=Not a C/C++ project. +CPathsPropertyPage.closed_project.message=Path information is not available for a closed project. +CPathsPropertyPage.error.title=Error Setting Propject Paths +CPathsPropertyPage.error.message=An error occurred while setting the project path +CPathsPropertyPage.unsavedchanges.title=Setting C/C++ Project Path +CPathsPropertyPage.unsavedchanges.message=The C/C++ Project path property page contains unsaved modifications. Do you want to save changes so that other build path related property pages can be updated? +CPathsPropertyPage.unsavedchanges.button.save=Apply +CPathsPropertyPage.unsavedchanges.button.discard=Discard +CPathsPropertyPage.unsavedchanges.button.ignore=Apply Later + + +BuildPathsBlock.tab.libraries=&Libraries + +# ------- BuildPathsBlock ------- + +CPathsBlock.path.up.button=&Up +CPathsBlock.path.down.button=&Down +CPathsBlock.path.checkall.button=Select &All +CPathsBlock.path.uncheckall.button=D&eselect All + +CPathsBlock.path.label=Path order and exported entries:\n(Exported entries are contributed to dependent projects) +CPathsBlock.warning.EntryMissing=Build path entry is missing: {0} +CPathsBlock.warning.EntriesMissing={0} build path entries are missing. + +CPathsBlock.operationdesc_project=Creating project... +CPathsBlock.operationdesc_c=Setting build paths... + +# ------- SourcePathEntryPage------- +SourcePathEntryPage.title=&Source +SourcePathEntryPage.description=Source Path for project +SourcePathEntryPage.folders.label=Source folders on build pat&h: +SourcePathEntryPage.folders.remove.button=&Remove +SourcePathEntryPage.folders.add.button=&Add Folder... +SourcePathEntryPath.folders.edit.button=&Edit... + +SourcePathEntryPage.ExistingSourceFolderDialog.new.title=Source Folder Selection +SourcePathEntryPage.ExistingSourceFolderDialog.new.description=&Choose source folders to be added to the build path: + +SourcePathEntryPage.ExistingSourceFolderDialog.edit.title=Source Folder Selection +SourcePathEntryPage.ExistingSourceFolderDialog.edit.description=&Select the source folder: + +SourcePathEntryPage.NewSourceFolderDialog.new.title=New Source Folder +SourcePathEntryPage.NewSourceFolderDialog.edit.title=Edit Source Folder + +SourcePathEntryPage.NewSourceFolderDialog.description=&Enter a path relative to ''{0}'': + +SourcePathEntryPage.exclusion_added.title=Source Folder Added +SourcePathEntryPage.exclusion_added.message=Exclusion filters have been added to nesting folders. + +# ------- OutputPathEntryPage------- + +OutputPathEntryPage.title=&Output +OutputPathEntryPage.description=Build Output locations +OutputPathEntryPage.folders.label=Output folders on build pat&h: +OutputPathEntryPage.folders.remove.button=&Remove +OutputPathEntryPage.folders.add.button=&Add Folder... +OutputPathEntryPage.folders.edit.button=&Edit... + +OutputPathEntryPage.ExistingOutputFolderDialog.new.title=Output Folder Selection +OutputPathEntryPage.ExistingOutputFolderDialog.new.description=&Choose Output folders to be added to the build path: + +OutputPathEntryPage.ExistingOutputFolderDialog.edit.title=Output Folder Selection +OutputPathEntryPage.ExistingOutputFolderDialog.edit.description=&Select the Output folder: + +OutputPathEntryPage.NewOutputFolderDialog.new.title=New Output Folder +OutputPathEntryPage.NewOutputFolderDialog.edit.title=Edit Output Folder + +OutputPathEntryPage.NewOutputFolderDialog.description=&Enter a path relative to ''{0}'': + +OutputPathEntryPage.exclusion_added.title=Output Folder Added +OutputPathEntryPage.exclusion_added.message=Exclusion filters have been added to nesting folders. + +# ------- ProjectsWorkbookPage------- +ProjectsEntryPage.title=&Projects +ProjectsEntryPage.description= +ProjectsEntryPage.projects.label=&Required projects on the build path: +ProjectsEntryPage.projects.checkall.button=Select &All +ProjectsEntryWorkbookPage.projects.uncheckall.button=&Deselect All + +# ------- LibrariesWorkbookPage------- + +LibrariesWorkbookPage.libraries.label=JARs &and class folders on the build path: +LibrariesWorkbookPage.libraries.remove.button=&Remove + +LibrariesWorkbookPage.libraries.addjar.button=Add &JARs... +LibrariesWorkbookPage.libraries.addextjar.button=Add E&xternal JARs... +LibrariesWorkbookPage.libraries.addvariable.button=Add &Variable... +LibrariesWorkbookPage.libraries.addlibrary.button=Add Li&brary... +LibrariesWorkbookPage.libraries.addclassfolder.button=Add Class &Folder... + + +LibrariesWorkbookPage.libraries.edit.button=&Edit... + +LibrariesWorkbookPage.ExistingClassFolderDialog.new.title=Class Folder Selection +LibrariesWorkbookPage.ExistingClassFolderDialog.new.description=&Choose class folders to be added to the build path: + +LibrariesWorkbookPage.ExistingClassFolderDialog.edit.title=Edit Class Folder +LibrariesWorkbookPage.ExistingClassFolderDialog.edit.description=&Select the class folder: + +LibrariesWorkbookPage.NewClassFolderDialog.new.title=New Class Folder +LibrariesWorkbookPage.NewClassFolderDialog.edit.title=Edit Class Folder + +LibrariesWorkbookPage.NewClassFolderDialog.description=&Enter a path relative to ''{0}'': + +LibrariesWorkbookPage.JARArchiveDialog.new.title=JAR Selection +LibrariesWorkbookPage.JARArchiveDialog.new.description=&Choose jar archives to be added to the build path: + +LibrariesWorkbookPage.JARArchiveDialog.edit.title=Edit JAR +LibrariesWorkbookPage.JARArchiveDialog.edit.description=&Select the jar archive: + +LibrariesWorkbookPage.ContainerDialog.new.title=Add Library +LibrariesWorkbookPage.ContainerDialog.edit.title=Edit Library + +LibrariesWorkbookPage.VariableSelectionDialog.new.title=New Variable Classpath Entry +LibrariesWorkbookPage.VariableSelectionDialog.edit.title=Edit Variable Entry + +LibrariesWorkbookPage.ExtJARArchiveDialog.new.title=JAR Selection + +LibrariesWorkbookPage.ExtJARArchiveDialog.edit.title=Edit JAR + +LibrariesWorkbookPage.SourceAttachmentDialog.title=Source For ''{0}'' +LibrariesWorkbookPage.JavadocPropertyDialog.title=Javadoc For ''{0}'' + +LibrariesWorkbookPage.AdvancedDialog.title=Add Classpath Entry +LibrariesWorkbookPage.AdvancedDialog.description=Select the entry to add to the classpath: +LibrariesWorkbookPage.AdvancedDialog.createfolder=Create &New Class Folder +LibrariesWorkbookPage.AdvancedDialog.addfolder=Add &Existing Class Folder +LibrariesWorkbookPage.AdvancedDialog.addcontainer=Add &Container: + +# ------- ExclusionPatternDialog ------- + +ExclusionPatternDialog.title=Source Folder Exclusion Patterns + +ExclusionPatternDialog.pattern.label=E&xclusion patterns for ''{0}'': +ExclusionPatternDialog.pattern.add=A&dd... +ExclusionPatternDialog.pattern.add.multiple=Add &Multiple... +ExclusionPatternDialog.pattern.remove=&Remove +ExclusionPatternDialog.pattern.edit=&Edit... + +ExclusionPatternDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection +ExclusionPatternDialog.ChooseExclusionPattern.description=&Choose folders or files to exclude: + +# ------- ExclusionPatternEntryDialog ------- + +ExclusionPatternEntryDialog.add.title=Add Exclusion Pattern +ExclusionPatternEntryDialog.edit.title=Edit Exclusion Pattern +ExclusionPatternEntryDialog.description=Enter a pattern for excluding files from the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'java/util/A*.java', 'java/util/', '**/Test*'. + +ExclusionPatternEntryDialog.pattern.label=E&xclusion pattern (Path relative to ''{0}''): +ExclusionPatternEntryDialog.pattern.button=Bro&wse... + +ExclusionPatternEntryDialog.error.empty=Enter a pattern. +ExclusionPatternEntryDialog.error.notrelative=Pattern must be a relative path. +ExclusionPatternEntryDialog.error.exists=Pattern already exists. + +ExclusionPatternEntryDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection +ExclusionPatternEntryDialog.ChooseExclusionPattern.description=&Choose a folder or file to exclude: + +OrderExportsPage.title=&Order and Export +OrderExportsPage.description= +# ------- ClasspathContainerDefaultPage------- + +ClasspathContainerDefaultPage.title=Classpath Container +ClasspathContainerDefaultPage.description=Select classpath container path. First segment is the container type. + +ClasspathContainerDefaultPage.path.label=&Classpath container path: + +ClasspathContainerDefaultPage.path.error.enterpath=Enter path. +ClasspathContainerDefaultPage.path.error.invalidpath=Invalid path. +ClasspathContainerDefaultPage.path.error.needssegment=Path needs at least one segment. +ClasspathContainerDefaultPage.path.error.alreadyexists=Entry already exists. + +# ------- ClasspathContainerSelectionPage------- + +ClasspathContainerSelectionPage.title=Add Library +ClasspathContainerSelectionPage.description=Select the library type to add. + +# ------- CPListLabelProvider ------- + +CPListLabelProvider.new=(new) +CPListLabelProvider.classcontainer=(class folder) +CPListLabelProvider.twopart={0} - {1} +CPListLabelProvider.willbecreated=(will be created) +CPListLabelProvider.none=(None) +CPListLabelProvider.source_attachment.label=Source attachment: +CPListLabelProvider.source_attachment_root.label=Source attachment root: +CPListLabelProvider.exclusion_filter.label=Exclusion filter: +CPListLabelProvider.exclusion_filter_separator=; +CPListLabelProvider.unknown_element.label=unknown element diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOrderExportPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOrderExportPage.java new file mode 100644 index 00000000000..7c3d3c66ae3 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOrderExportPage.java @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.List; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; + +public class CPathOrderExportPage extends CPathBasePage { + + private ListDialogField fCPathList; + + public CPathOrderExportPage(ListDialogField cPathList) { + super(CPathEntryMessages.getString("OrderExportsPage.title")); //$NON-NLS-1$ + setDescription(CPathEntryMessages.getString("OrderExportsPage.description")); //$NON-NLS-1$ + fCPathList = cPathList; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + + Composite composite = new Composite(parent, SWT.NONE); + setControl(composite); + + LayoutUtil.doDefaultLayout(composite, new DialogField[]{fCPathList}, true); + LayoutUtil.setHorizontalGrabbing(fCPathList.getListControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fCPathList.setButtonsMinWidth(buttonBarWidth); + } + + public Image getImage() { + return CPluginImages.get(CPluginImages.IMG_OBJS_ORDER); + } + /* + * @see BuildPathBasePage#getSelection + */ + public List getSelection() { + return fCPathList.getSelectedElements(); + } + + /* + * @see BuildPathBasePage#setSelection + */ + public void setSelection(List selElements) { + fCPathList.selectElements(new StructuredSelection(selElements)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathBasePage#isEntryKind(int) + */ + public boolean isEntryKind(int kind) { + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#performDefaults() + */ + public void performDefaults() { + } + +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java new file mode 100644 index 00000000000..8b398798067 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathOutputEntryPage.java @@ -0,0 +1,561 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.dialogs.NewFolderDialog; +import org.eclipse.ui.model.BaseWorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +public class CPathOutputEntryPage extends CPathBasePage { + + private ListDialogField fCPathList; + private ICProject fCurrCProject; + private IPath fProjPath; + + private IWorkspaceRoot fWorkspaceRoot; + + private TreeListDialogField fOutputList; + + private final int IDX_ADD = 0; + private final int IDX_EDIT = 2; + private final int IDX_REMOVE = 3; + + /** + * @param title + */ + public CPathOutputEntryPage(ListDialogField cPathList) { + super(CPathEntryMessages.getString("OutputPathEntryPage.title")); //$NON-NLS-1$ + setDescription(CPathEntryMessages.getString("OutputPathEntryPage.description")); //$NON-NLS-1$ + + fWorkspaceRoot = CUIPlugin.getWorkspace().getRoot(); + fCPathList = cPathList; + + OutputContainerAdapter adapter = new OutputContainerAdapter(); + + String[] buttonLabels; + + buttonLabels = new String[] { + /* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("OutputPathEntryPage.folders.add.button"), //$NON-NLS-1$ + /* 1 */ null, /* 2 = IDX_EDIT */CPathEntryMessages.getString("OutputPathEntryPage.folders.edit.button"), //$NON-NLS-1$ + /* 3 = IDX_REMOVE */CPathEntryMessages.getString("OutputPathEntryPage.folders.remove.button") //$NON-NLS-1$ + }; + + fOutputList = new TreeListDialogField(adapter, buttonLabels, new CPListLabelProvider()); + fOutputList.setDialogFieldListener(adapter); + fOutputList.setLabelText(CPathEntryMessages.getString("OutputPathEntryPage.folders.label")); //$NON-NLS-1$ + + fOutputList.setViewerSorter(new CPListElementSorter()); + fOutputList.enableButton(IDX_EDIT, false); + } + + + public Image getImage() { + return CPluginImages.get(CPluginImages.IMG_OBJS_CONTAINER); + } + + public void init(ICProject cproject) { + fCurrCProject = cproject; + fProjPath = fCurrCProject.getProject().getFullPath(); + updateFoldersList(); + } + + private void updateFoldersList() { + ArrayList folders = new ArrayList(); + + List cpelements = fCPathList.getElements(); + for (int i = 0; i < cpelements.size(); i++) { + CPListElement cpe = (CPListElement) cpelements.get(i); + if (cpe.getEntryKind() == IPathEntry.CDT_OUTPUT) { + folders.add(cpe); + } + } + fOutputList.setElements(folders); + + for (int i = 0; i < folders.size(); i++) { + CPListElement cpe = (CPListElement) folders.get(i); + IPath[] patterns = (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION); + if (patterns.length > 0) { + fOutputList.expandElement(cpe, 3); + } + } + } + + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + Composite composite = new Composite(parent, SWT.NONE); + + LayoutUtil.doDefaultLayout(composite, new DialogField[] { fOutputList}, true); + LayoutUtil.setHorizontalGrabbing(fOutputList.getTreeControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fOutputList.setButtonsMinWidth(buttonBarWidth); + + // expand + List elements = fOutputList.getElements(); + for (int i = 0; i < elements.size(); i++) { + CPListElement elem = (CPListElement) elements.get(i); + IPath[] patterns = (IPath[]) elem.getAttribute(CPListElement.EXCLUSION); + if (patterns.length > 0) { + fOutputList.expandElement(elem, 3); + } + } + setControl(composite); + } + + private class OutputContainerAdapter implements ITreeListAdapter, IDialogFieldListener { + + private final Object[] EMPTY_ARR = new Object[0]; + + // -------- IListAdapter -------- + public void customButtonPressed(TreeListDialogField field, int index) { + outputPageCustomButtonPressed(field, index); + } + + public void selectionChanged(TreeListDialogField field) { + outputPageSelectionChanged(field); + } + + public void doubleClicked(TreeListDialogField field) { + outputPageDoubleClicked(field); + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + outputPageKeyPressed(field, event); + } + + public Object[] getChildren(TreeListDialogField field, Object element) { + if (element instanceof CPListElement) { + return ((CPListElement) element).getChildren(); + } + return EMPTY_ARR; + } + + public Object getParent(TreeListDialogField field, Object element) { + if (element instanceof CPListElementAttribute) { + return ((CPListElementAttribute) element).getParent(); + } + return null; + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + return (element instanceof CPListElement); + } + + // ---------- IDialogFieldListener -------- + public void dialogFieldChanged(DialogField field) { + outputPageDialogFieldChanged(field); + } + + } + + protected void outputPageKeyPressed(TreeListDialogField field, KeyEvent event) { + if (field == fOutputList) { + if (event.character == SWT.DEL && event.stateMask == 0) { + List selection = field.getSelectedElements(); + if (canRemove(selection)) { + removeEntry(); + } + } + } + } + + protected void outputPageDoubleClicked(TreeListDialogField field) { + if (field == fOutputList) { + List selection = field.getSelectedElements(); + if (canEdit(selection)) { + editEntry(); + } + } + } + + private boolean hasFolders(IContainer container) { + try { + IResource[] members = container.members(); + for (int i = 0; i < members.length; i++) { + if (members[i] instanceof IContainer) { + return true; + } + } + } catch (CoreException e) { + // ignore + } + return false; + } + + protected void outputPageCustomButtonPressed(DialogField field, int index) { + if (field == fOutputList) { + if (index == IDX_ADD) { + List elementsToAdd = new ArrayList(10); + IProject project = fCurrCProject.getProject(); + if (project.exists()) { + if (hasFolders(project)) { + CPListElement[] srcentries = openOutputContainerDialog(null); + if (srcentries != null) { + for (int i = 0; i < srcentries.length; i++) { + elementsToAdd.add(srcentries[i]); + } + } + } else { + CPListElement entry = openNewOutputContainerDialog(null, true); + if (entry != null) { + elementsToAdd.add(entry); + } + } + } else { + CPListElement entry = openNewOutputContainerDialog(null, false); + if (entry != null) { + elementsToAdd.add(entry); + } + } + if (!elementsToAdd.isEmpty()) { + HashSet modifiedElements = new HashSet(); + askForAddingExclusionPatternsDialog(elementsToAdd, modifiedElements); + + fOutputList.addElements(elementsToAdd); + fOutputList.postSetSelection(new StructuredSelection(elementsToAdd)); + + if (!modifiedElements.isEmpty()) { + for (Iterator iter = modifiedElements.iterator(); iter.hasNext();) { + Object elem = iter.next(); + fOutputList.refresh(elem); + fOutputList.expandElement(elem, 3); + } + } + + } + } else if (index == IDX_EDIT) { + editEntry(); + } else if (index == IDX_REMOVE) { + removeEntry(); + } + } + } + + private void editEntry() { + List selElements = fOutputList.getSelectedElements(); + if (selElements.size() != 1) { + return; + } + Object elem = selElements.get(0); + if (fOutputList.getIndexOfElement(elem) != -1) { + editElementEntry((CPListElement) elem); + } else if (elem instanceof CPListElementAttribute) { + editAttributeEntry((CPListElementAttribute) elem); + } + } + + private void editElementEntry(CPListElement elem) { + CPListElement res = null; + + res = openNewOutputContainerDialog(elem, true); + + if (res != null) { + fOutputList.replaceElement(elem, res); + } + } + + private void editAttributeEntry(CPListElementAttribute elem) { + String key = elem.getKey(); + if (key.equals(CPListElement.EXCLUSION)) { + CPListElement selElement = elem.getParent(); + ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement); + if (dialog.open() == Window.OK) { + selElement.setAttribute(CPListElement.EXCLUSION, dialog.getExclusionPattern()); + fOutputList.refresh(); + fCPathList.dialogFieldChanged(); // validate + } + } + } + + protected void outputPageSelectionChanged(DialogField field) { + List selected = fOutputList.getSelectedElements(); + fOutputList.enableButton(IDX_EDIT, canEdit(selected)); + fOutputList.enableButton(IDX_REMOVE, canRemove(selected)); + } + + private void removeEntry() { + List selElements = fOutputList.getSelectedElements(); + for (int i = selElements.size() - 1; i >= 0; i--) { + Object elem = selElements.get(i); + if (elem instanceof CPListElementAttribute) { + CPListElementAttribute attrib = (CPListElementAttribute) elem; + String key = attrib.getKey(); + Object value = key.equals(CPListElement.EXCLUSION) ? new Path[0] : null; + attrib.getParent().setAttribute(key, value); + selElements.remove(i); + } + } + if (selElements.isEmpty()) { + fOutputList.refresh(); + fCPathList.dialogFieldChanged(); // validate + } else { + fOutputList.removeElements(selElements); + } + } + + private boolean canRemove(List selElements) { + if (selElements.size() == 0) { + return false; + } + for (int i = 0; i < selElements.size(); i++) { + Object elem = selElements.get(i); + if (elem instanceof CPListElementAttribute) { + CPListElementAttribute attrib = (CPListElementAttribute) elem; + if (attrib.getKey().equals(CPListElement.EXCLUSION)) { + if (((IPath[]) attrib.getValue()).length == 0) { + return false; + } + } else if (attrib.getValue() == null) { + return false; + } + } else if (elem instanceof CPListElement) { + CPListElement curr = (CPListElement) elem; + if (curr.getParentContainer() != null) { + return false; + } + } + } + return true; + } + + private boolean canEdit(List selElements) { + if (selElements.size() != 1) { + return false; + } + Object elem = selElements.get(0); + if (elem instanceof CPListElement) { + return false; + } + if (elem instanceof CPListElementAttribute) { + return true; + } + return false; + } + + private void outputPageDialogFieldChanged(DialogField field) { + if (fCurrCProject == null) { + // not initialized + return; + } + + if (field == fOutputList) { + updateCPathList(); + } + } + + private void updateCPathList() { + List srcelements = fOutputList.getElements(); + + List cpelements = fCPathList.getElements(); + int nEntries = cpelements.size(); + // backwards, as entries will be deleted + int lastRemovePos = nEntries; + int afterLastSourcePos = 0; + for (int i = nEntries - 1; i >= 0; i--) { + CPListElement cpe = (CPListElement) cpelements.get(i); + int kind = cpe.getEntryKind(); + if (isEntryKind(kind)) { + if (!srcelements.remove(cpe)) { + cpelements.remove(i); + lastRemovePos = i; + } else if (lastRemovePos == nEntries) { + afterLastSourcePos = i + 1; + } + } + } + + if (!srcelements.isEmpty()) { + int insertPos = Math.min(afterLastSourcePos, lastRemovePos); + cpelements.addAll(insertPos, srcelements); + } + + if (lastRemovePos != nEntries || !srcelements.isEmpty()) { + fCPathList.setElements(cpelements); + } + } + + private CPListElement openNewOutputContainerDialog(CPListElement existing, boolean includeLinked) { + if (includeLinked) { + NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); + if (dialog.open() == Window.OK) { + IResource createdFolder = (IResource) dialog.getResult()[0]; + return newCPOutputElement(createdFolder); + } + return null; + } else { + String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ + + IProject proj = fCurrCProject.getProject(); + NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), + existing); + dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ + fProjPath.toString())); + if (dialog.open() == Window.OK) { + IResource folder = dialog.getSourceFolder(); + return newCPOutputElement(folder); + } + return null; + } + } + + private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) { + fixNestingConflicts(newEntries, fOutputList.getElements(), modifiedEntries); + if (!modifiedEntries.isEmpty()) { + String title = CPathEntryMessages.getString("OutputPathEntryPage.exclusion_added.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("OutputPathEntryPage.exclusion_added.message"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), title, message); + } + } + + private CPListElement[] openOutputContainerDialog(CPListElement existing) { + + Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class}; + List existingContainers = getExistingContainers(null); + + IProject[] allProjects = fWorkspaceRoot.getProjects(); + ArrayList rejectedElements = new ArrayList(allProjects.length); + IProject currProject = fCurrCProject.getProject(); + for (int i = 0; i < allProjects.length; i++) { + if (!allProjects[i].equals(currProject)) { + rejectedElements.add(allProjects[i]); + } + } + + ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray()); + + ILabelProvider lp = new WorkbenchLabelProvider(); + ITreeContentProvider cp = new BaseWorkbenchContentProvider(); + + String title = (existing == null) ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.edit.title"); //$NON-NLS-1$ + String message = (existing == null) ? CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.new.description") //$NON-NLS-1$ + : CPathEntryMessages.getString("OutputPathEntryPage.ExistingOutputFolderDialog.edit.description"); //$NON-NLS-1$ + + MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); + dialog.setExisting(existingContainers.toArray()); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.addFilter(filter); + dialog.setInput(fCurrCProject.getProject().getParent()); + if (existing == null) { + dialog.setInitialFocus(fCurrCProject.getProject()); + } else { + dialog.setInitialFocus(existing.getResource()); + } + if (dialog.open() == Window.OK) { + Object[] elements = dialog.getResult(); + CPListElement[] res = new CPListElement[elements.length]; + for (int i = 0; i < res.length; i++) { + IResource elem = (IResource) elements[i]; + res[i] = newCPOutputElement(elem); + } + return res; + } + return null; + } + + private List getExistingContainers(CPListElement existing) { + List res = new ArrayList(); + List cplist = fOutputList.getElements(); + for (int i = 0; i < cplist.size(); i++) { + CPListElement elem = (CPListElement) cplist.get(i); + if (elem != existing) { + IResource resource = elem.getResource(); + if (resource instanceof IContainer) { // defensive code + res.add(resource); + } + } + } + return res; + } + + private CPListElement newCPOutputElement(IResource res) { + Assert.isNotNull(res); + return new CPListElement(fCurrCProject, IPathEntry.CDT_OUTPUT, res.getFullPath(), res); + } + + /* + * @see BuildPathBasePage#getSelection + */ + public List getSelection() { + return fOutputList.getSelectedElements(); + } + + /* + * @see BuildPathBasePage#setSelection + */ + public void setSelection(List selElements) { + fOutputList.selectElements(new StructuredSelection(selElements)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathBasePage#isEntryKind(int) + */ + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_OUTPUT; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() + */ + public void performDefaults() { + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java new file mode 100644 index 00000000000..e80d6f4b519 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathProjectsEntryPage.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.ICModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +public class CPathProjectsEntryPage extends CPathBasePage { + + private CheckedListDialogField fProjectsList; + ICProject fCurrCProject; + private ListDialogField fCPathList; + + public CPathProjectsEntryPage(ListDialogField cPathList) { + super(CPathEntryMessages.getString("ProjectsEntryPage.title")); //$NON-NLS-1$ + setDescription(CPathEntryMessages.getString("ProjectsEntryPage.description")); //$NON-NLS-1$ + ProjectsListListener listener = new ProjectsListListener(); + + String[] buttonLabels = new String[] { /* 0 */CPathEntryMessages.getString("ProjectsEntryPage.projects.checkall.button"), //$NON-NLS-1$ + /* 1 */CPathEntryMessages.getString("ProjectsEntryWorkbookPage.projects.uncheckall.button")}; //$NON-NLS-1$ + + fProjectsList = new CheckedListDialogField(null, buttonLabels, new CPListLabelProvider()); + fProjectsList.setDialogFieldListener(listener); + fProjectsList.setLabelText(CPathEntryMessages.getString("ProjectsEntryPage.projects.label")); //$NON-NLS-1$ + fProjectsList.setCheckAllButtonIndex(0); + fProjectsList.setUncheckAllButtonIndex(1); + + fProjectsList.setViewerSorter(new CPListElementSorter()); + fCPathList = cPathList; + } + + public Image getImage() { + return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() + */ + public void performDefaults() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + + Composite composite = new Composite(parent, SWT.NONE); + + setControl(composite); + + LayoutUtil.doDefaultLayout(composite, new DialogField[] { fProjectsList}, true); + LayoutUtil.setHorizontalGrabbing(fProjectsList.getListControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fProjectsList.setButtonsMinWidth(buttonBarWidth); + } + + private class ProjectsListListener implements IDialogFieldListener { + + // ---------- IDialogFieldListener -------- + + public void dialogFieldChanged(DialogField field) { + if (fCurrCProject != null) { + // already initialized + updateCPathList(); + } + } + } + + public void init(ICProject cproject) { + updateProjectsList(cproject); + } + + void updateProjectsList(ICProject currCProject) { + ICModel cmodel = currCProject.getCModel(); + ICProject[] cprojects = cmodel.getCProjects(); + + List projects = new ArrayList(cprojects.length); + + // a vector remembering all projects that dont have to be added anymore + List existingProjects = new ArrayList(cprojects.length); + existingProjects.add(currCProject.getProject()); + + final List checkedProjects = new ArrayList(cprojects.length); + // add the projects-cpentries that are already on the C Path + List cpelements = fCPathList.getElements(); + for (int i = cpelements.size() - 1; i >= 0; i--) { + CPListElement cpelem = (CPListElement) cpelements.get(i); + if (isEntryKind(cpelem.getEntryKind())) { + existingProjects.add(cpelem.getResource()); + projects.add(cpelem); + checkedProjects.add(cpelem); + } + } + + for (int i = 0; i < cprojects.length; i++) { + IProject proj = cprojects[i].getProject(); + if (!existingProjects.contains(proj)) { + projects.add(new CPListElement(fCurrCProject, IPathEntry.CDT_PROJECT, proj.getFullPath(), proj)); + } + } + + fProjectsList.setElements(projects); + fProjectsList.setCheckedElements(checkedProjects); + fCurrCProject = currCProject; + } + + void updateCPathList() { + List projelements = fProjectsList.getCheckedElements(); + + boolean remove = false; + List pelements = fCPathList.getElements(); + // backwards, as entries will be deleted + for (int i = pelements.size() - 1; i >= 0; i--) { + CPListElement pe = (CPListElement) pelements.get(i); + if (isEntryKind(pe.getEntryKind())) { + if (!projelements.remove(pe)) { + pelements.remove(i); + remove = true; + } + } + } + for (int i = 0; i < projelements.size(); i++) { + pelements.add(projelements.get(i)); + } + if (remove || (projelements.size() > 0)) { + fCPathList.setElements(pelements); + } + } + + /* + * @see BuildPathBasePage#getSelection + */ + public List getSelection() { + return fProjectsList.getSelectedElements(); + } + + /* + * @see BuildPathBasePage#setSelection + */ + public void setSelection(List selElements) { + fProjectsList.selectElements(new StructuredSelection(selElements)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathBasePage#isEntryKind(int) + */ + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_PROJECT; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathPropertyPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathPropertyPage.java new file mode 100644 index 00000000000..70906bbed43 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathPropertyPage.java @@ -0,0 +1,214 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; +import org.eclipse.cdt.internal.ui.util.ExceptionHandler; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * @see PropertyPage + */ +public class CPathPropertyPage extends PropertyPage implements IStatusChangeListener { + + private static final String PAGE_SETTINGS = "CPathsPropertyPage"; //$NON-NLS-1$ + private static final String INDEX = "pageIndex"; //$NON-NLS-1$ + + CPathTabBlock fCPathsBlock; + + /** + * @see PropertyPage#createContents + */ + protected Control createContents(Composite parent) { + IProject project = getProject(); + Control result; + if (project == null || !isCProject(project)) { + result = createWithoutCProject(parent); + } else if (!project.isOpen()) { + result = createForClosedProject(parent); + } else { + result = createWithCProject(parent, project); + } + Dialog.applyDialogFont(result); + return result; + } + + private IDialogSettings getSettings() { + IDialogSettings cSettings = CUIPlugin.getDefault().getDialogSettings(); + IDialogSettings pageSettings = cSettings.getSection(PAGE_SETTINGS); + if (pageSettings == null) { + pageSettings = cSettings.addNewSection(PAGE_SETTINGS); + pageSettings.put(INDEX, 3); + } + return pageSettings; + } + + /* + * Content for valid projects. + */ + private Control createWithCProject(Composite parent, IProject project) { + fCPathsBlock = new CPathTabBlock(this, getSettings().getInt(INDEX)); + fCPathsBlock.init(CoreModel.getDefault().create(project), null); + return fCPathsBlock.createContents(parent); + } + + /* + * Content for non-C projects. + */ + private Control createWithoutCProject(Composite parent) { + Label label = new Label(parent, SWT.LEFT); + label.setText(CPathEntryMessages.getString("CPathsPropertyPage.no_C_project.message")); //$NON-NLS-1$ + + fCPathsBlock = null; + setValid(true); + return label; + } + + /* + * Content for closed projects. + */ + private Control createForClosedProject(Composite parent) { + Label label = new Label(parent, SWT.LEFT); + label.setText(CPathEntryMessages.getString("CPathsPropertyPage.closed_project.message")); //$NON-NLS-1$ + + fCPathsBlock = null; + setValid(true); + return label; + } + + public void setVisible(boolean visible) { + if (fCPathsBlock != null) { + if (!visible) { + if (fCPathsBlock.hasChangesInDialog()) { + String title= CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.title"); //$NON-NLS-1$ + String message= CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.message"); //$NON-NLS-1$ + String[] buttonLabels= new String[] { + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.save"), //$NON-NLS-1$ + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.discard"), //$NON-NLS-1$ + CPathEntryMessages.getString("CPathsPropertyPage.unsavedchanges.button.ignore") //$NON-NLS-1$ + }; + MessageDialog dialog= new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, buttonLabels, 0); + int res= dialog.open(); + if (res == 0) { + performOk(); + } else if (res == 1) { + fCPathsBlock.init(CoreModel.getDefault().create(getProject()), null); + } else { + fCPathsBlock.initializeTimeStamps(); + } + } + } else { + if (!fCPathsBlock.hasChangesInDialog() && fCPathsBlock.hasChangesInCPathFile()) { + fCPathsBlock.init(CoreModel.getDefault().create(getProject()), null); + } + } + } + super.setVisible(visible); + } + + private IProject getProject() { + IAdaptable adaptable = getElement(); + if (adaptable != null) { + ICElement elem = (ICElement) adaptable.getAdapter(ICElement.class); + if (elem instanceof ICProject) { + return ((ICProject) elem).getProject(); + } + } + return null; + } + + private boolean isCProject(IProject proj) { + try { + return proj.hasNature(CProjectNature.C_NATURE_ID); + } catch (CoreException e) { + CUIPlugin.getDefault().log(e); + } + return false; + } + + /* + * @see IPreferencePage#performOk + */ + public boolean performOk() { + if (fCPathsBlock != null) { + getSettings().put(INDEX, fCPathsBlock.getPageIndex()); + + Shell shell = getControl().getShell(); + IRunnableWithProgress runnable = new IRunnableWithProgress() { + + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + fCPathsBlock.configureCProject(monitor); + } catch (CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); + try { + new ProgressMonitorDialog(shell).run(true, true, op); + } catch (InvocationTargetException e) { + String title = CPathEntryMessages.getString("CPathsPropertyPage.error.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("CPathsPropertyPage.error.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, shell, title, message); + return false; + } catch (InterruptedException e) { + // cancelled + return false; + } + } + return true; + } + + /* + * (non-Javadoc) + * + * @see IStatusChangeListener#statusChanged + */ + public void statusChanged(IStatus status) { + setValid(!status.matches(IStatus.ERROR)); + StatusUtil.applyToStatusLine(this, status); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.IPreferencePage#performCancel() + */ + public boolean performCancel() { + if (fCPathsBlock != null) { + getSettings().put(INDEX, fCPathsBlock.getPageIndex()); + } + return super.performCancel(); + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java new file mode 100644 index 00000000000..70644b99dd0 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathSourceEntryPage.java @@ -0,0 +1,560 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ITreeListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.TreeListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.dialogs.NewFolderDialog; +import org.eclipse.ui.model.BaseWorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +public class CPathSourceEntryPage extends CPathBasePage { + + private ListDialogField fClassPathList; + private ICProject fCurrCProject; + private IPath fProjPath; + + private IWorkspaceRoot fWorkspaceRoot; + + private TreeListDialogField fFoldersList; + + private final int IDX_ADD = 0; + private final int IDX_EDIT = 2; + private final int IDX_REMOVE = 3; + + /** + * @param title + */ + public CPathSourceEntryPage(ListDialogField classPathList) { + super(CPathEntryMessages.getString("SourcePathEntryPage.title")); //$NON-NLS-1$ + setDescription(CPathEntryMessages.getString("SourcePathEntryPage.description")); //$NON-NLS-1$ + + fWorkspaceRoot = CUIPlugin.getWorkspace().getRoot(); + fClassPathList = classPathList; + + SourceContainerAdapter adapter = new SourceContainerAdapter(); + + String[] buttonLabels; + + buttonLabels = new String[] { + /* 0 = IDX_ADDEXIST */CPathEntryMessages.getString("SourcePathEntryPage.folders.add.button"), //$NON-NLS-1$ + /* 1 */null, /* 2 = IDX_EDIT */CPathEntryMessages.getString("SourcePathEntryPath.folders.edit.button"), //$NON-NLS-1$ + /* 3 = IDX_REMOVE */CPathEntryMessages.getString("SourcePathEntryPage.folders.remove.button") //$NON-NLS-1$ + }; + + fFoldersList = new TreeListDialogField(adapter, buttonLabels, new CPListLabelProvider()); + fFoldersList.setDialogFieldListener(adapter); + fFoldersList.setLabelText(CPathEntryMessages.getString("SourcePathEntryPage.folders.label")); //$NON-NLS-1$ + + fFoldersList.setViewerSorter(new CPListElementSorter()); + fFoldersList.enableButton(IDX_EDIT, false); + } + + + public Image getImage() { + return CPluginImages.get(CPluginImages.IMG_OBJS_SOURCE_ROOT); + } + + public void init(ICProject cproject) { + fCurrCProject = cproject; + fProjPath = fCurrCProject.getProject().getFullPath(); + updateFoldersList(); + } + + private void updateFoldersList() { + ArrayList folders = new ArrayList(); + + List cpelements = fClassPathList.getElements(); + for (int i = 0; i < cpelements.size(); i++) { + CPListElement cpe = (CPListElement) cpelements.get(i); + if (cpe.getEntryKind() == IPathEntry.CDT_SOURCE) { + folders.add(cpe); + } + } + fFoldersList.setElements(folders); + + for (int i = 0; i < folders.size(); i++) { + CPListElement cpe = (CPListElement) folders.get(i); + IPath[] patterns = (IPath[]) cpe.getAttribute(CPListElement.EXCLUSION); + if (patterns.length > 0) { + fFoldersList.expandElement(cpe, 3); + } + } + } + + public void createControl(Composite parent) { + PixelConverter converter = new PixelConverter(parent); + Composite composite = new Composite(parent, SWT.NONE); + + LayoutUtil.doDefaultLayout(composite, new DialogField[] { fFoldersList}, true); + LayoutUtil.setHorizontalGrabbing(fFoldersList.getTreeControl(null)); + + int buttonBarWidth = converter.convertWidthInCharsToPixels(24); + fFoldersList.setButtonsMinWidth(buttonBarWidth); + + // expand + List elements = fFoldersList.getElements(); + for (int i = 0; i < elements.size(); i++) { + CPListElement elem = (CPListElement) elements.get(i); + IPath[] patterns = (IPath[]) elem.getAttribute(CPListElement.EXCLUSION); + if (patterns.length > 0) { + fFoldersList.expandElement(elem, 3); + } + } + setControl(composite); + } + + private class SourceContainerAdapter implements ITreeListAdapter, IDialogFieldListener { + + private final Object[] EMPTY_ARR = new Object[0]; + + // -------- IListAdapter -------- + public void customButtonPressed(TreeListDialogField field, int index) { + sourcePageCustomButtonPressed(field, index); + } + + public void selectionChanged(TreeListDialogField field) { + sourcePageSelectionChanged(field); + } + + public void doubleClicked(TreeListDialogField field) { + sourcePageDoubleClicked(field); + } + + public void keyPressed(TreeListDialogField field, KeyEvent event) { + sourcePageKeyPressed(field, event); + } + + public Object[] getChildren(TreeListDialogField field, Object element) { + if (element instanceof CPListElement) { + return ((CPListElement) element).getChildren(); + } + return EMPTY_ARR; + } + + public Object getParent(TreeListDialogField field, Object element) { + if (element instanceof CPListElementAttribute) { + return ((CPListElementAttribute) element).getParent(); + } + return null; + } + + public boolean hasChildren(TreeListDialogField field, Object element) { + return (element instanceof CPListElement); + } + + // ---------- IDialogFieldListener -------- + public void dialogFieldChanged(DialogField field) { + sourcePageDialogFieldChanged(field); + } + + } + + protected void sourcePageKeyPressed(TreeListDialogField field, KeyEvent event) { + if (field == fFoldersList) { + if (event.character == SWT.DEL && event.stateMask == 0) { + List selection = field.getSelectedElements(); + if (canRemove(selection)) { + removeEntry(); + } + } + } + } + + protected void sourcePageDoubleClicked(TreeListDialogField field) { + if (field == fFoldersList) { + List selection = field.getSelectedElements(); + if (canEdit(selection)) { + editEntry(); + } + } + } + + private boolean hasFolders(IContainer container) { + try { + IResource[] members = container.members(); + for (int i = 0; i < members.length; i++) { + if (members[i] instanceof IContainer) { + return true; + } + } + } catch (CoreException e) { + // ignore + } + return false; + } + + protected void sourcePageCustomButtonPressed(DialogField field, int index) { + if (field == fFoldersList) { + if (index == IDX_ADD) { + List elementsToAdd = new ArrayList(10); + IProject project = fCurrCProject.getProject(); + if (project.exists()) { + if (hasFolders(project)) { + CPListElement[] srcentries = openSourceContainerDialog(null); + if (srcentries != null) { + for (int i = 0; i < srcentries.length; i++) { + elementsToAdd.add(srcentries[i]); + } + } + } else { + CPListElement entry = openNewSourceContainerDialog(null, true); + if (entry != null) { + elementsToAdd.add(entry); + } + } + } else { + CPListElement entry = openNewSourceContainerDialog(null, false); + if (entry != null) { + elementsToAdd.add(entry); + } + } + if (!elementsToAdd.isEmpty()) { + HashSet modifiedElements = new HashSet(); + askForAddingExclusionPatternsDialog(elementsToAdd, modifiedElements); + + fFoldersList.addElements(elementsToAdd); + fFoldersList.postSetSelection(new StructuredSelection(elementsToAdd)); + + if (!modifiedElements.isEmpty()) { + for (Iterator iter = modifiedElements.iterator(); iter.hasNext();) { + Object elem = iter.next(); + fFoldersList.refresh(elem); + fFoldersList.expandElement(elem, 3); + } + } + + } + } else if (index == IDX_EDIT) { + editEntry(); + } else if (index == IDX_REMOVE) { + removeEntry(); + } + } + } + + private void editEntry() { + List selElements = fFoldersList.getSelectedElements(); + if (selElements.size() != 1) { + return; + } + Object elem = selElements.get(0); + if (fFoldersList.getIndexOfElement(elem) != -1) { + editElementEntry((CPListElement) elem); + } else if (elem instanceof CPListElementAttribute) { + editAttributeEntry((CPListElementAttribute) elem); + } + } + + private void editElementEntry(CPListElement elem) { + CPListElement res = null; + + res = openNewSourceContainerDialog(elem, true); + + if (res != null) { + fFoldersList.replaceElement(elem, res); + } + } + + private void editAttributeEntry(CPListElementAttribute elem) { + String key = elem.getKey(); + if (key.equals(CPListElement.EXCLUSION)) { + CPListElement selElement = elem.getParent(); + ExclusionPatternDialog dialog = new ExclusionPatternDialog(getShell(), selElement); + if (dialog.open() == Window.OK) { + selElement.setAttribute(CPListElement.EXCLUSION, dialog.getExclusionPattern()); + fFoldersList.refresh(); + fClassPathList.dialogFieldChanged(); // validate + } + } + } + + protected void sourcePageSelectionChanged(DialogField field) { + List selected = fFoldersList.getSelectedElements(); + fFoldersList.enableButton(IDX_EDIT, canEdit(selected)); + fFoldersList.enableButton(IDX_REMOVE, canRemove(selected)); + } + + private void removeEntry() { + List selElements = fFoldersList.getSelectedElements(); + for (int i = selElements.size() - 1; i >= 0; i--) { + Object elem = selElements.get(i); + if (elem instanceof CPListElementAttribute) { + CPListElementAttribute attrib = (CPListElementAttribute) elem; + String key = attrib.getKey(); + Object value = key.equals(CPListElement.EXCLUSION) ? new Path[0] : null; + attrib.getParent().setAttribute(key, value); + selElements.remove(i); + } + } + if (selElements.isEmpty()) { + fFoldersList.refresh(); + fClassPathList.dialogFieldChanged(); // validate + } else { + fFoldersList.removeElements(selElements); + } + } + + private boolean canRemove(List selElements) { + if (selElements.size() == 0) { + return false; + } + for (int i = 0; i < selElements.size(); i++) { + Object elem = selElements.get(i); + if (elem instanceof CPListElementAttribute) { + CPListElementAttribute attrib = (CPListElementAttribute) elem; + if (attrib.getKey().equals(CPListElement.EXCLUSION)) { + if (((IPath[]) attrib.getValue()).length == 0) { + return false; + } + } else if (attrib.getValue() == null) { + return false; + } + } else if (elem instanceof CPListElement) { + CPListElement curr = (CPListElement) elem; + if (curr.getParentContainer() != null) { + return false; + } + } + } + return true; + } + + private boolean canEdit(List selElements) { + if (selElements.size() != 1) { + return false; + } + Object elem = selElements.get(0); + if (elem instanceof CPListElement) { + return false; + } + if (elem instanceof CPListElementAttribute) { + return true; + } + return false; + } + + private void sourcePageDialogFieldChanged(DialogField field) { + if (fCurrCProject == null) { + // not initialized + return; + } + + if (field == fFoldersList) { + updateClasspathList(); + } + } + + private void updateClasspathList() { + List srcelements = fFoldersList.getElements(); + + List cpelements = fClassPathList.getElements(); + int nEntries = cpelements.size(); + // backwards, as entries will be deleted + int lastRemovePos = nEntries; + int afterLastSourcePos = 0; + for (int i = nEntries - 1; i >= 0; i--) { + CPListElement cpe = (CPListElement) cpelements.get(i); + int kind = cpe.getEntryKind(); + if (isEntryKind(kind)) { + if (!srcelements.remove(cpe)) { + cpelements.remove(i); + lastRemovePos = i; + } else if (lastRemovePos == nEntries) { + afterLastSourcePos = i + 1; + } + } + } + + if (!srcelements.isEmpty()) { + int insertPos = Math.min(afterLastSourcePos, lastRemovePos); + cpelements.addAll(insertPos, srcelements); + } + + if (lastRemovePos != nEntries || !srcelements.isEmpty()) { + fClassPathList.setElements(cpelements); + } + } + + private CPListElement openNewSourceContainerDialog(CPListElement existing, boolean includeLinked) { + if (includeLinked) { + NewFolderDialog dialog = new NewFolderDialog(getShell(), fCurrCProject.getProject()); + if (dialog.open() == Window.OK) { + IResource createdFolder = (IResource) dialog.getResult()[0]; + return newCPSourceElement(createdFolder); + } + return null; + } else { + String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.NewSourceFolderDialog.edit.title"); //$NON-NLS-1$ + + IProject proj = fCurrCProject.getProject(); + NewSourceFolderDialog dialog = new NewSourceFolderDialog(getShell(), title, proj, getExistingContainers(existing), + existing); + dialog.setMessage(CPathEntryMessages.getFormattedString("SourcePathEntryPage.NewSourceFolderDialog.description", //$NON-NLS-1$ + fProjPath.toString())); + if (dialog.open() == Window.OK) { + IResource folder = dialog.getSourceFolder(); + return newCPSourceElement(folder); + } + return null; + } + } + + private void askForAddingExclusionPatternsDialog(List newEntries, Set modifiedEntries) { + fixNestingConflicts(newEntries, fFoldersList.getElements(), modifiedEntries); + if (!modifiedEntries.isEmpty()) { + String title = CPathEntryMessages.getString("SourcePathEntryPage.exclusion_added.title"); //$NON-NLS-1$ + String message = CPathEntryMessages.getString("SourcePathEntryPage.exclusion_added.message"); //$NON-NLS-1$ + MessageDialog.openInformation(getShell(), title, message); + } + } + + private CPListElement[] openSourceContainerDialog(CPListElement existing) { + + Class[] acceptedClasses = new Class[] { IProject.class, IFolder.class}; + List existingContainers = getExistingContainers(null); + + IProject[] allProjects = fWorkspaceRoot.getProjects(); + ArrayList rejectedElements = new ArrayList(allProjects.length); + IProject currProject = fCurrCProject.getProject(); + for (int i = 0; i < allProjects.length; i++) { + if (!allProjects[i].equals(currProject)) { + rejectedElements.add(allProjects[i]); + } + } + + ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray()); + + ILabelProvider lp = new WorkbenchLabelProvider(); + ITreeContentProvider cp = new BaseWorkbenchContentProvider(); + + String title = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.title") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.edit.title"); //$NON-NLS-1$ + String message = (existing == null) ? CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.new.description") //$NON-NLS-1$ + : CPathEntryMessages.getString("SourcePathEntryPage.ExistingSourceFolderDialog.edit.description"); //$NON-NLS-1$ + + MultipleFolderSelectionDialog dialog = new MultipleFolderSelectionDialog(getShell(), lp, cp); + dialog.setExisting(existingContainers.toArray()); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.addFilter(filter); + dialog.setInput(fCurrCProject.getProject().getParent()); + if (existing == null) { + dialog.setInitialFocus(fCurrCProject.getProject()); + } else { + dialog.setInitialFocus(existing.getResource()); + } + if (dialog.open() == Window.OK) { + Object[] elements = dialog.getResult(); + CPListElement[] res = new CPListElement[elements.length]; + for (int i = 0; i < res.length; i++) { + IResource elem = (IResource) elements[i]; + res[i] = newCPSourceElement(elem); + } + return res; + } + return null; + } + + private List getExistingContainers(CPListElement existing) { + List res = new ArrayList(); + List cplist = fFoldersList.getElements(); + for (int i = 0; i < cplist.size(); i++) { + CPListElement elem = (CPListElement) cplist.get(i); + if (elem != existing) { + IResource resource = elem.getResource(); + if (resource instanceof IContainer) { // defensive code + res.add(resource); + } + } + } + return res; + } + + private CPListElement newCPSourceElement(IResource res) { + Assert.isNotNull(res); + return new CPListElement(fCurrCProject, IPathEntry.CDT_SOURCE, res.getFullPath(), res); + } + + /* + * @see BuildPathBasePage#getSelection + */ + public List getSelection() { + return fFoldersList.getSelectedElements(); + } + + /* + * @see BuildPathBasePage#setSelection + */ + public void setSelection(List selElements) { + fFoldersList.selectElements(new StructuredSelection(selElements)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathBasePage#isEntryKind(int) + */ + public boolean isEntryKind(int kind) { + return kind == IPathEntry.CDT_SOURCE; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) + */ + public void performApply(IProgressMonitor monitor) throws CoreException { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.AbstractCOptionPage#performDefaults() + */ + public void performDefaults() { + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java new file mode 100644 index 00000000000..6ce5aed8f6a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/CPathTabBlock.java @@ -0,0 +1,511 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICModelStatus; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IPathEntry; +import org.eclipse.cdt.internal.core.model.CModelStatus; +import org.eclipse.cdt.internal.ui.dialogs.IStatusChangeListener; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.dialogs.StatusUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.CheckedListDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.ui.dialogs.ICOptionContainer; +import org.eclipse.cdt.ui.dialogs.ICOptionPage; +import org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class CPathTabBlock extends TabFolderOptionBlock implements ICOptionContainer { + + private CheckedListDialogField fCPathList; + + private StatusInfo fCPathStatus; + private StatusInfo fBuildPathStatus; + + private ICProject fCurrCProject; + + private String fUserSettingsTimeStamp; + private long fFileTimeStamp; + + private int fPageIndex, fPageCount; + + private CPathSourceEntryPage fSourcePage; + private CPathProjectsEntryPage fProjectsPage; + private CPathOutputEntryPage fOutputPage; + //private LibrariesWorkbookPage fLibrariesPage; + + private CPathBasePage fCurrPage; + + private IStatusChangeListener fContext; + + private CPathOrderExportPage fOrderExportPage; + + private class BuildPathAdapter implements IDialogFieldListener { + + // ---------- IDialogFieldListener -------- + public void dialogFieldChanged(DialogField field) { + buildPathDialogFieldChanged(field); + } + } + + void buildPathDialogFieldChanged(DialogField field) { + if (field == fCPathList) { + updateClassPathStatus(); + } + doStatusLineUpdate(); + } + + public CPathTabBlock(IStatusChangeListener context, int pageToShow) { + super(true); + fContext = context; + fPageIndex = pageToShow; + + String[] buttonLabels = new String[] { /* 0 */CPathEntryMessages.getString("CPathsBlock.path.up.button"), //$NON-NLS-1$ + /* 1 */CPathEntryMessages.getString("CPathsBlock.path.down.button"), //$NON-NLS-1$ + /* 2 */null, /* 3 */CPathEntryMessages.getString("CPathsBlock.path.checkall.button"), //$NON-NLS-1$ + /* 4 */CPathEntryMessages.getString("CPathsBlock.path.uncheckall.button") //$NON-NLS-1$ + + }; + BuildPathAdapter adapter = new BuildPathAdapter(); + + fCPathList = new CheckedListDialogField(null, buttonLabels, new CPListLabelProvider()); + fCPathList.setDialogFieldListener(adapter); + fCPathList.setLabelText(CPathEntryMessages.getString("CPathsBlock.path.label")); //$NON-NLS-1$ + fCPathList.setUpButtonIndex(0); + fCPathList.setDownButtonIndex(1); + fCPathList.setCheckAllButtonIndex(3); + fCPathList.setUncheckAllButtonIndex(4); + + fCPathStatus = new StatusInfo(); + fBuildPathStatus = new StatusInfo(); + + fCurrCProject = null; + setOptionContainer(this); + } + + protected void addTabs() { + fSourcePage = new CPathSourceEntryPage(fCPathList); + addPage(fSourcePage); + fOutputPage = new CPathOutputEntryPage(fCPathList); + addPage(fOutputPage); + fProjectsPage = new CPathProjectsEntryPage(fCPathList); + addPage(fProjectsPage); + fOrderExportPage = new CPathOrderExportPage(fCPathList); + addPage(fOrderExportPage); + } + + private void addPage(CPathBasePage page) { + addTab(page); + if (fPageIndex == fPageCount) { + fCurrPage = page; + } + fPageCount++; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock#getStartPage() + */ + protected ICOptionPage getStartPage() { + if (fCurrPage == null) { + return super.getStartPage(); + } + return fCurrPage; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock#createContents(org.eclipse.swt.widgets.Composite) + */ + public Control createContents(Composite parent) { + Control control = super.createContents(parent); + if (fCurrCProject != null) { + fSourcePage.init(fCurrCProject); + fOutputPage.init(fCurrCProject); + fProjectsPage.init(fCurrCProject); + //fLibrariesPage.init(fCurrCProject); + } + Dialog.applyDialogFont(control); + return control; + } + + /** + * Initializes the classpath for the given project. Multiple calls to init + * are allowed, but all existing settings will be cleared and replace by the + * given or default paths. + * + * @param jproject + * The java project to configure. Does not have to exist. + * @param outputLocation + * The output location to be set in the page. If null + * is passed, jdt default settings are used, or - if the project is + * an existing Java project- the output location of the existing + * project + * @param classpathEntries + * The classpath entries to be set in the page. If null + * is passed, jdt default settings are used, or - if the project is + * an existing Java project - the classpath entries of the existing + * project + */ + public void init(ICProject cproject, IPathEntry[] cpathEntries) { + fCurrCProject = cproject; + boolean projectExists = false; + List newClassPath = null; + + IProject project = fCurrCProject.getProject(); + projectExists = (project.exists() && project.getFile(".cdtproject").exists()); //$NON-NLS-1$ + if (projectExists) { + if (cpathEntries == null) { + try { + cpathEntries = fCurrCProject.getRawPathEntries(); + } catch (CModelException e) { + } + } + } + if (cpathEntries != null) { + newClassPath = getExistingEntries(cpathEntries); + } + if (newClassPath == null) { + newClassPath = getDefaultCPath(cproject); + } + + List exportedEntries = new ArrayList(); + for (int i = 0; i < newClassPath.size(); i++) { + CPListElement curr = (CPListElement) newClassPath.get(i); + if (curr.isExported() && curr.getEntryKind() != IPathEntry.CDT_SOURCE) { + exportedEntries.add(curr); + } + } + + fCPathList.setElements(newClassPath); + fCPathList.setCheckedElements(exportedEntries); + + if (fProjectsPage != null) { + fSourcePage.init(fCurrCProject); + fOutputPage.init(fCurrCProject); + fProjectsPage.init(fCurrCProject); + // fLibrariesPage.init(fCurrCProject); + } + + doStatusLineUpdate(); + initializeTimeStamps(); + } + + private ArrayList getExistingEntries(IPathEntry[] cPathEntries) { + ArrayList newCPath = new ArrayList(); + for (int i = 0; i < cPathEntries.length; i++) { + IPathEntry curr = cPathEntries[i]; + newCPath.add(CPListElement.createFromExisting(curr, fCurrCProject)); + } + return newCPath; + } + + private String getEncodedSettings() { + StringBuffer buf = new StringBuffer(); + + int nElements = fCPathList.getSize(); + buf.append('[').append(nElements).append(']'); + for (int i = 0; i < nElements; i++) { + CPListElement elem = (CPListElement) fCPathList.getElement(i); + elem.appendEncodedSettings(buf); + } + return buf.toString(); + } + + public boolean hasChangesInDialog() { + String currSettings = getEncodedSettings(); + return !currSettings.equals(fUserSettingsTimeStamp); + } + + public boolean hasChangesInCPathFile() { + IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ + return fFileTimeStamp != file.getModificationStamp(); + } + + public void initializeTimeStamps() { + IFile file = fCurrCProject.getProject().getFile(".cdtproject"); //$NON-NLS-1$ + fFileTimeStamp = file.getModificationStamp(); + fUserSettingsTimeStamp = getEncodedSettings(); + } + + private List getDefaultCPath(ICProject cproj) { + List list = new ArrayList(); + // IResource srcFolder; + // IPreferenceStore store= PreferenceConstants.getPreferenceStore(); + // String sourceFolderName= + // store.getString(PreferenceConstants.SRCBIN_SRCNAME); + // if (store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ) + // && sourceFolderName.length() > 0) { + // srcFolder= jproj.getProject().getFolder(sourceFolderName); + // } else { + // srcFolder= jproj.getProject(); + // } + // + // list.add(new CPListElement(jproj, IClasspathEntry.CPE_SOURCE, + // srcFolder.getFullPath(), srcFolder)); + // + // IClasspathEntry[] jreEntries= + // PreferenceConstants.getDefaultJRELibrary(); + // list.addAll(getExistingEntries(jreEntries)); + return list; + } + + // -------- public api -------- + + /** + * @return Returns the Java project. Can return + * null if the page has not + * been initialized. + */ + public ICProject getCProject() { + return fCurrCProject; + } + + /** + * @return Returns the current class path (raw). Note that the entries + * returned must not be valid. + */ + public IPathEntry[] getRawCPath() { + List elements = fCPathList.getElements(); + int nElements = elements.size(); + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = 0; i < nElements; i++) { + CPListElement currElement = (CPListElement) elements.get(i); + entries[i] = currElement.getPathEntry(); + } + return entries; + } + + // -------- evaluate default settings -------- + + // private List getDefaultClassPath(IJavaProject jproj) { + // List list= new ArrayList(); + // IResource srcFolder; + // IPreferenceStore store= PreferenceConstants.getPreferenceStore(); + // String sourceFolderName= + // store.getString(PreferenceConstants.SRCBIN_SRCNAME); + // if (store.getBoolean(PreferenceConstants.SRCBIN_FOLDERS_IN_NEWPROJ) && + // sourceFolderName.length() > 0) { + // srcFolder= jproj.getProject().getFolder(sourceFolderName); + // } else { + // srcFolder= jproj.getProject(); + // } + // + // list.add(new CPListElement(jproj, IClasspathEntry.CPE_SOURCE, + // srcFolder.getFullPath(), srcFolder)); + // + // IPathEntry[] jreEntries= PreferenceConstants.getDefaultJRELibrary(); + // list.addAll(getExistingEntries(jreEntries)); + // return list; + // } + // + + private void doStatusLineUpdate() { + IStatus res = findMostSevereStatus(); + fContext.statusChanged(res); + } + + private IStatus findMostSevereStatus() { + return StatusUtil.getMostSevere(new IStatus[] { fCPathStatus, fBuildPathStatus}); + } + + /** + * Validates the build path. + */ + public void updateClassPathStatus() { + fCPathStatus.setOK(); + + List elements = fCPathList.getElements(); + + CPListElement entryMissing = null; + int nEntriesMissing = 0; + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = elements.size() - 1; i >= 0; i--) { + CPListElement currElement = (CPListElement) elements.get(i); + boolean isChecked = fCPathList.isChecked(currElement); + if ( currElement.getEntryKind() == IPathEntry.CDT_SOURCE) { + if (isChecked) { + fCPathList.setCheckedWithoutUpdate(currElement, false); + } + } else { + currElement.setExported(isChecked); + } + + entries[i] = currElement.getPathEntry(); + if (currElement.isMissing()) { + nEntriesMissing++; + if (entryMissing == null) { + entryMissing = currElement; + } + } + } + + if (nEntriesMissing > 0) { + if (nEntriesMissing == 1) { + fCPathStatus.setWarning(CPathEntryMessages.getFormattedString("BuildPathsBlock.warning.EntryMissing", //$NON-NLS-1$ + entryMissing.getPath().toString())); + } else { + fCPathStatus.setWarning(CPathEntryMessages.getFormattedString("BuildPathsBlock.warning.EntriesMissing", //$NON-NLS-1$ + String.valueOf(nEntriesMissing))); + } + } + + /* + * if (fCurrJProject.hasClasspathCycle(entries)) { + * fClassPathStatus.setWarning(NewWizardMessages.getString("BuildPathsBlock.warning.CycleInClassPath")); + * //$NON-NLS-1$ } + */ + updateBuildPathStatus(); + } + + private void updateBuildPathStatus() { + List elements = fCPathList.getElements(); + IPathEntry[] entries = new IPathEntry[elements.size()]; + + for (int i = elements.size() - 1; i >= 0; i--) { + CPListElement currElement = (CPListElement) elements.get(i); + entries[i] = currElement.getPathEntry(); + } + + ICModelStatus status = CModelStatus.VERIFIED_OK; // CoreModelUtil.validateCPathEntries(fCurrCProject, entries); + if (!status.isOK()) { + fBuildPathStatus.setError(status.getMessage()); + return; + } + fBuildPathStatus.setOK(); + } + + // -------- creation ------------------------------- + + public void configureCProject(IProgressMonitor monitor) throws CoreException, InterruptedException { + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + monitor.setTaskName(CPathEntryMessages.getString("CPathsBlock.operationdesc_c")); //$NON-NLS-1$ + monitor.beginTask("", 10); //$NON-NLS-1$ + + try { + internalConfigureCProject(fCPathList.getElements(), monitor); + } finally { + monitor.done(); + } + } + + /* + * Creates the Java project and sets the configured build path and output + * location. If the project already exists only build paths are updated. + */ + private void internalConfigureCProject(List cPathEntries, IProgressMonitor monitor) throws CoreException, InterruptedException { + // 10 monitor steps to go + + monitor.worked(2); + + int nEntries = cPathEntries.size(); + IPathEntry[] classpath = new IPathEntry[nEntries]; + + // create and set the class path + for (int i = 0; i < nEntries; i++) { + CPListElement entry = ((CPListElement) cPathEntries.get(i)); + IResource res = entry.getResource(); + if ((res instanceof IFolder) && !res.exists()) { + createFolder((IFolder) res, true, true, null); + } + classpath[i] = entry.getPathEntry(); + } + + monitor.worked(1); + + fCurrCProject.setRawPathEntries(classpath, new SubProgressMonitor(monitor, 7)); + initializeTimeStamps(); + } + + /** + * Creates a folder and all parent folders if not existing. Project must + * exist. org.eclipse.ui.dialogs.ContainerGenerator is too + * heavy (creates a runnable) + */ + private void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException { + if (!folder.exists()) { + IContainer parent = folder.getParent(); + if (parent instanceof IFolder) { + createFolder((IFolder) parent, force, local, null); + } + folder.create(force, local, monitor); + } + } + + + // -------- tab switching ---------- + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.TabFolderOptionBlock#setCurrentPage(org.eclipse.cdt.ui.dialogs.ICOptionPage) + */ + public void setCurrentPage(ICOptionPage page) { + super.setCurrentPage(page); + CPathBasePage newPage = (CPathBasePage) page; + if (fCurrPage != null) { + List selection = fCurrPage.getSelection(); + if (!selection.isEmpty()) { + newPage.setSelection(selection); + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#updateContainer() + */ + public void updateContainer() { + update(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getProject() + */ + public IProject getProject() { + return fCurrCProject.getProject(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionContainer#getPreferences() + */ + public Preferences getPreferences() { + return null; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternDialog.java new file mode 100644 index 00000000000..b1f06f29662 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternDialog.java @@ -0,0 +1,278 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.cdt.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry; +import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator; +import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IListAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.ListDialogField; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.views.navigator.ResourceSorter; + +public class ExclusionPatternDialog extends StatusDialog { + + private static class ExclusionPatternLabelProvider extends LabelProvider { + + public Image getImage(Object element) { + ImageDescriptorRegistry registry= CUIPlugin.getImageDescriptorRegistry(); + return registry.get(CPluginImages.DESC_OBJS_EXCLUSION_FILTER_ATTRIB); + } + + public String getText(Object element) { + return (String) element; + } + + } + + + private ListDialogField fExclusionPatternList; + private CPListElement fCurrElement; + private IProject fCurrProject; + + private IContainer fCurrSourceFolder; + + private static final int IDX_ADD= 0; + private static final int IDX_ADD_MULTIPLE= 1; + private static final int IDX_EDIT= 2; + private static final int IDX_REMOVE= 4; + + + public ExclusionPatternDialog(Shell parent, CPListElement entryToEdit) { + super(parent); + fCurrElement= entryToEdit; + setTitle(CPathEntryMessages.getString("ExclusionPatternDialog.title")); //$NON-NLS-1$ + + String label= CPathEntryMessages.getFormattedString("ExclusionPatternDialog.pattern.label", entryToEdit.getPath().makeRelative().toString()); //$NON-NLS-1$ + + String[] buttonLabels= new String[] { + /* IDX_ADD */ CPathEntryMessages.getString("ExclusionPatternDialog.pattern.add"), //$NON-NLS-1$ + /* IDX_ADD_MULTIPLE */ CPathEntryMessages.getString("ExclusionPatternDialog.pattern.add.multiple"), //$NON-NLS-1$ + /* IDX_EDIT */ CPathEntryMessages.getString("ExclusionPatternDialog.pattern.edit"), //$NON-NLS-1$ + null, + /* IDX_REMOVE */ CPathEntryMessages.getString("ExclusionPatternDialog.pattern.remove") //$NON-NLS-1$ + }; + + ExclusionPatternAdapter adapter= new ExclusionPatternAdapter(); + + fExclusionPatternList= new ListDialogField(adapter, buttonLabels, new ExclusionPatternLabelProvider()); + fExclusionPatternList.setDialogFieldListener(adapter); + fExclusionPatternList.setLabelText(label); + fExclusionPatternList.setRemoveButtonIndex(IDX_REMOVE); + fExclusionPatternList.enableButton(IDX_EDIT, false); + + fCurrProject= entryToEdit.getCProject().getProject(); + IWorkspaceRoot root= fCurrProject.getWorkspace().getRoot(); + IResource res= root.findMember(entryToEdit.getPath()); + if (res instanceof IContainer) { + fCurrSourceFolder= (IContainer) res; + } + + IPath[] pattern= (IPath[]) entryToEdit.getAttribute(CPListElement.EXCLUSION); + + ArrayList elements= new ArrayList(pattern.length); + for (int i= 0; i < pattern.length; i++) { + elements.add(pattern[i].toString()); + } + fExclusionPatternList.setElements(elements); + fExclusionPatternList.selectFirstElement(); + fExclusionPatternList.enableButton(IDX_ADD_MULTIPLE, fCurrSourceFolder != null); + } + + + protected Control createDialogArea(Composite parent) { + Composite composite= (Composite)super.createDialogArea(parent); + + Composite inner= new Composite(composite, SWT.NONE); + GridLayout layout= new GridLayout(); + layout.marginHeight= 0; + layout.marginWidth= 0; + layout.numColumns= 2; + inner.setLayout(layout); + + fExclusionPatternList.doFillIntoGrid(inner, 3); + LayoutUtil.setHorizontalSpan(fExclusionPatternList.getLabelControl(null), 2); + + applyDialogFont(composite); + return composite; + } + + protected void doCustomButtonPressed(ListDialogField field, int index) { + if (index == IDX_ADD) { + addEntry(); + } else if (index == IDX_EDIT) { + editEntry(); + } else if (index == IDX_ADD_MULTIPLE) { + addMultipleEntries(); + } + } + + protected void doDoubleClicked(ListDialogField field) { + editEntry(); + } + + protected void doSelectionChanged(ListDialogField field) { + List selected= field.getSelectedElements(); + fExclusionPatternList.enableButton(IDX_EDIT, canEdit(selected)); + } + + private boolean canEdit(List selected) { + return selected.size() == 1; + } + + private void editEntry() { + + List selElements= fExclusionPatternList.getSelectedElements(); + if (selElements.size() != 1) { + return; + } + List existing= fExclusionPatternList.getElements(); + String entry= (String) selElements.get(0); + ExclusionPatternEntryDialog dialog= new ExclusionPatternEntryDialog(getShell(), entry, existing, fCurrElement); + if (dialog.open() == Window.OK) { + fExclusionPatternList.replaceElement(entry, dialog.getExclusionPattern()); + } + } + + private void addEntry() { + List existing= fExclusionPatternList.getElements(); + ExclusionPatternEntryDialog dialog= new ExclusionPatternEntryDialog(getShell(), null, existing, fCurrElement); + if (dialog.open() == Window.OK) { + fExclusionPatternList.addElement(dialog.getExclusionPattern()); + } + } + + + + // -------- ExclusionPatternAdapter -------- + + private class ExclusionPatternAdapter implements IListAdapter, IDialogFieldListener { + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#customButtonPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField, int) + */ + public void customButtonPressed(ListDialogField field, int index) { + doCustomButtonPressed(field, index); + } + + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#selectionChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField) + */ + public void selectionChanged(ListDialogField field) { + doSelectionChanged(field); + } + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter#doubleClicked(org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField) + */ + public void doubleClicked(ListDialogField field) { + doDoubleClicked(field); + } + + /** + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener#dialogFieldChanged(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) + */ + public void dialogFieldChanged(DialogField field) { + } + + } + + protected void doStatusLineUpdate() { + } + + protected void checkIfPatternValid() { + } + + + public IPath[] getExclusionPattern() { + IPath[] res= new IPath[fExclusionPatternList.getSize()]; + for (int i= 0; i < res.length; i++) { + String entry= (String) fExclusionPatternList.getElement(i); + res[i]= new Path(entry); + } + return res; + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); +// WorkbenchHelp.setHelp(newShell, ICHelpContextIds.EXCLUSION_PATTERN_DIALOG); + } + + private void addMultipleEntries() { + Class[] acceptedClasses= new Class[] { IFolder.class, IFile.class }; + ISelectionStatusValidator validator= new TypedElementSelectionValidator(acceptedClasses, true); + ViewerFilter filter= new TypedViewerFilter(acceptedClasses); + + ILabelProvider lp= new WorkbenchLabelProvider(); + ITreeContentProvider cp= new WorkbenchContentProvider(); + + IResource initialElement= null; + + ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(getShell(), lp, cp); + dialog.setTitle(CPathEntryMessages.getString("ExclusionPatternDialog.ChooseExclusionPattern.title")); //$NON-NLS-1$ + dialog.setValidator(validator); + dialog.setMessage(CPathEntryMessages.getString("ExclusionPatternDialog.ChooseExclusionPattern.description")); //$NON-NLS-1$ + dialog.addFilter(filter); + dialog.setInput(fCurrSourceFolder); + dialog.setInitialSelection(initialElement); + dialog.setSorter(new ResourceSorter(ResourceSorter.NAME)); + + if (dialog.open() == Window.OK) { + Object[] objects= dialog.getResult(); + int existingSegments= fCurrSourceFolder.getFullPath().segmentCount(); + + for (int i= 0; i < objects.length; i++) { + IResource curr= (IResource) objects[i]; + IPath path= curr.getFullPath().removeFirstSegments(existingSegments).makeRelative(); + String res; + if (curr instanceof IContainer) { + res= path.addTrailingSeparator().toString(); + } else { + res= path.toString(); + } + fExclusionPatternList.addElement(res); + } + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java new file mode 100644 index 00000000000..3d27fe5c705 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/ExclusionPatternEntryDialog.java @@ -0,0 +1,229 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.List; + +import org.eclipse.cdt.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.wizards.TypedElementSelectionValidator; +import org.eclipse.cdt.internal.ui.wizards.TypedViewerFilter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IStringButtonAdapter; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.LayoutUtil; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringButtonDialogField; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.views.navigator.ResourceSorter; + +public class ExclusionPatternEntryDialog extends StatusDialog { + + private StringButtonDialogField fExclusionPatternDialog; + private StatusInfo fExclusionPatternStatus; + + private IContainer fCurrSourceFolder; + private String fExclusionPattern; + private List fExistingPatterns; + + public ExclusionPatternEntryDialog(Shell parent, String patternToEdit, List existingPatterns, CPListElement entryToEdit) { + super(parent); + fExistingPatterns = existingPatterns; + if (patternToEdit == null) { + setTitle(CPathEntryMessages.getString("ExclusionPatternEntryDialog.add.title")); //$NON-NLS-1$ + } else { + setTitle(CPathEntryMessages.getString("ExclusionPatternEntryDialog.edit.title")); //$NON-NLS-1$ + fExistingPatterns.remove(patternToEdit); + } + + IWorkspaceRoot root = entryToEdit.getCProject().getProject().getWorkspace().getRoot(); + IResource res = root.findMember(entryToEdit.getPath()); + if (res instanceof IContainer) { + fCurrSourceFolder = (IContainer) res; + } + + fExclusionPatternStatus = new StatusInfo(); + + String label = CPathEntryMessages.getFormattedString("ExclusionPatternEntryDialog.pattern.label", //$NON-NLS-1$ + entryToEdit.getPath().makeRelative().toString()); + + ExclusionPatternAdapter adapter = new ExclusionPatternAdapter(); + fExclusionPatternDialog = new StringButtonDialogField(adapter); + fExclusionPatternDialog.setLabelText(label); + fExclusionPatternDialog.setButtonLabel(CPathEntryMessages.getString("ExclusionPatternEntryDialog.pattern.button")); //$NON-NLS-1$ + fExclusionPatternDialog.setDialogFieldListener(adapter); + fExclusionPatternDialog.enableButton(fCurrSourceFolder != null); + + if (patternToEdit == null) { + fExclusionPatternDialog.setText(""); //$NON-NLS-1$ + } else { + fExclusionPatternDialog.setText(patternToEdit.toString()); + } + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + + int widthHint = convertWidthInCharsToPixels(60); + + Composite inner = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 2; + inner.setLayout(layout); + + Label description = new Label(inner, SWT.WRAP); + description.setText(CPathEntryMessages.getString("ExclusionPatternEntryDialog.description")); //$NON-NLS-1$ + GridData gd = new GridData(); + gd.horizontalSpan = 2; + gd.widthHint = convertWidthInCharsToPixels(80); + description.setLayoutData(gd); + + fExclusionPatternDialog.doFillIntoGrid(inner, 3); + + LayoutUtil.setWidthHint(fExclusionPatternDialog.getLabelControl(null), widthHint); + LayoutUtil.setHorizontalSpan(fExclusionPatternDialog.getLabelControl(null), 2); + + LayoutUtil.setWidthHint(fExclusionPatternDialog.getTextControl(null), widthHint); + LayoutUtil.setHorizontalGrabbing(fExclusionPatternDialog.getTextControl(null)); + + fExclusionPatternDialog.postSetFocusOnDialogField(parent.getDisplay()); + applyDialogFont(composite); + return composite; + } + + // -------- ExclusionPatternAdapter -------- + + private class ExclusionPatternAdapter implements IDialogFieldListener, IStringButtonAdapter { + + // -------- IDialogFieldListener + + public void dialogFieldChanged(DialogField field) { + doStatusLineUpdate(); + } + + public void changeControlPressed(DialogField field) { + doChangeControlPressed(); + } + } + + protected void doChangeControlPressed() { + IPath pattern = chooseExclusionPattern(); + if (pattern != null) { + fExclusionPatternDialog.setText(pattern.toString()); + } + } + + protected void doStatusLineUpdate() { + checkIfPatternValid(); + updateStatus(fExclusionPatternStatus); + } + + protected void checkIfPatternValid() { + String pattern = fExclusionPatternDialog.getText().trim(); + if (pattern.length() == 0) { + fExclusionPatternStatus.setError(CPathEntryMessages.getString("ExclusionPatternEntryDialog.error.empty")); //$NON-NLS-1$ + return; + } + IPath path = new Path(pattern); + if (path.isAbsolute() || path.getDevice() != null) { + fExclusionPatternStatus.setError(CPathEntryMessages.getString("ExclusionPatternEntryDialog.error.notrelative")); //$NON-NLS-1$ + return; + } + if (fExistingPatterns.contains(pattern)) { + fExclusionPatternStatus.setError(CPathEntryMessages.getString("ExclusionPatternEntryDialog.error.exists")); //$NON-NLS-1$ + return; + } + + fExclusionPattern = pattern; + fExclusionPatternStatus.setOK(); + } + + public String getExclusionPattern() { + return fExclusionPattern; + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + // WorkbenchHelp.setHelp(newShell, + // ICHelpContextIds.EXCLUSION_PATTERN_DIALOG); + } + + // ---------- util method ------------ + + private IPath chooseExclusionPattern() { + Class[] acceptedClasses = new Class[] { IFolder.class, IFile.class}; + ISelectionStatusValidator validator = new TypedElementSelectionValidator(acceptedClasses, false); + ViewerFilter filter = new TypedViewerFilter(acceptedClasses); + + ILabelProvider lp = new WorkbenchLabelProvider(); + ITreeContentProvider cp = new WorkbenchContentProvider(); + + IPath initialPath = new Path(fExclusionPatternDialog.getText()); + IResource initialElement = null; + IContainer curr = fCurrSourceFolder; + int nSegments = initialPath.segmentCount(); + for (int i = 0; i < nSegments; i++) { + IResource elem = curr.findMember(initialPath.segment(i)); + if (elem != null) { + initialElement = elem; + } + if (elem instanceof IContainer) { + curr = (IContainer) elem; + } else { + break; + } + } + + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp); + dialog.setTitle(CPathEntryMessages.getString("ExclusionPatternEntryDialog.ChooseExclusionPattern.title")); //$NON-NLS-1$ + dialog.setValidator(validator); + dialog.setMessage(CPathEntryMessages.getString("ExclusionPatternEntryDialog.ChooseExclusionPattern.description")); //$NON-NLS-1$ + dialog.addFilter(filter); + dialog.setInput(fCurrSourceFolder); + dialog.setInitialSelection(initialElement); + dialog.setSorter(new ResourceSorter(ResourceSorter.NAME)); + + if (dialog.open() == Window.OK) { + IResource res = (IResource) dialog.getFirstResult(); + IPath path = res.getFullPath().removeFirstSegments(fCurrSourceFolder.getFullPath().segmentCount()).makeRelative(); + if (res instanceof IContainer) { + return path.addTrailingSeparator(); + } else { + return path; + } + } + return null; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java new file mode 100644 index 00000000000..7c3a11d5fb4 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/MultipleFolderSelectionDialog.java @@ -0,0 +1,315 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.dialogs.NewFolderDialog; +import org.eclipse.ui.dialogs.SelectionStatusDialog; +import org.eclipse.ui.views.navigator.ResourceSorter; + +/** + */ +public class MultipleFolderSelectionDialog extends SelectionStatusDialog implements ISelectionChangedListener { + + private CheckboxTreeViewer fViewer; + + private ILabelProvider fLabelProvider; + private ITreeContentProvider fContentProvider; + private List fFilters; + + private Object fInput; + private Button fNewFolderButton; + private IContainer fSelectedContainer; + private Set fExisting; + private Object fFocusElement; + + public MultipleFolderSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) { + super(parent); + fLabelProvider = labelProvider; + fContentProvider = contentProvider; + + setSelectionResult(null); + setStatusLineAboveButtons(true); + + int shellStyle = getShellStyle(); + setShellStyle(shellStyle | SWT.MAX | SWT.RESIZE); + + fExisting = null; + fFocusElement = null; + fFilters = null; + } + + public void setExisting(Object[] existing) { + fExisting = new HashSet(); + for (int i = 0; i < existing.length; i++) { + fExisting.add(existing[i]); + } + } + + /** + * Sets the tree input. + * + * @param input + * the tree input. + */ + public void setInput(Object input) { + fInput = input; + } + + /** + * Adds a filter to the tree viewer. + * + * @param filter + * a filter. + */ + public void addFilter(ViewerFilter filter) { + if (fFilters == null) + fFilters = new ArrayList(4); + + fFilters.add(filter); + } + + /** + * Handles cancel button pressed event. + */ + protected void cancelPressed() { + setSelectionResult(null); + super.cancelPressed(); + } + + /* + * @see SelectionStatusDialog#computeResult() + */ + protected void computeResult() { + Object[] checked = fViewer.getCheckedElements(); + if (fExisting == null) { + if (checked.length == 0) { + checked = null; + } + } else { + ArrayList res = new ArrayList(); + for (int i = 0; i < checked.length; i++) { + Object elem = checked[i]; + if (!fExisting.contains(elem)) { + res.add(elem); + } + } + if (!res.isEmpty()) { + checked = res.toArray(); + } else { + checked = null; + } + } + setSelectionResult(checked); + } + + void access$superCreate() { + super.create(); + } + + /* + * @see Window#create() + */ + public void create() { + + BusyIndicator.showWhile(null, new Runnable() { + + public void run() { + access$superCreate(); + + fViewer.setCheckedElements(getInitialElementSelections().toArray()); + + fViewer.expandToLevel(2); + if (fExisting != null) { + for (Iterator iter = fExisting.iterator(); iter.hasNext();) { + fViewer.reveal(iter.next()); + } + } + + updateOKStatus(); + } + }); + + } + + /** + * Creates the tree viewer. + * + * @param parent + * the parent composite + * @return the tree viewer + */ + protected CheckboxTreeViewer createTreeViewer(Composite parent) { + fViewer = new CheckboxTreeViewer(parent, SWT.BORDER); + + fViewer.setContentProvider(fContentProvider); + fViewer.setLabelProvider(fLabelProvider); + fViewer.addCheckStateListener(new ICheckStateListener() { + + public void checkStateChanged(CheckStateChangedEvent event) { + updateOKStatus(); + } + }); + + fViewer.setSorter(new ResourceSorter(ResourceSorter.NAME)); + if (fFilters != null) { + for (int i = 0; i != fFilters.size(); i++) + fViewer.addFilter((ViewerFilter) fFilters.get(i)); + } + + fViewer.setInput(fInput); + + return fViewer; + } + + /** + * + */ + protected void updateOKStatus() { + computeResult(); + if (getResult() != null) { + updateStatus(new StatusInfo()); + } else { + updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$ + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + + createMessageArea(composite); + CheckboxTreeViewer treeViewer = createTreeViewer(composite); + + GridData data = new GridData(GridData.FILL_BOTH); + data.widthHint = convertWidthInCharsToPixels(60); + data.heightHint = convertHeightInCharsToPixels(18); + + Tree treeWidget = treeViewer.getTree(); + treeWidget.setLayoutData(data); + treeWidget.setFont(composite.getFont()); + + Button button = new Button(composite, SWT.PUSH); + button.setText(NewWizardMessages.getString("MultipleFolderSelectionDialog.button")); //$NON-NLS-1$ + button.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent event) { + newFolderButtonPressed(); + } + }); + button.setFont(composite.getFont()); + + data = new GridData(); + data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); + button.setLayoutData(data); + fNewFolderButton = button; + + treeViewer.addSelectionChangedListener(this); + if (fExisting != null) { + Object[] existing = fExisting.toArray(); + treeViewer.setGrayedElements(existing); + setInitialSelections(existing); + } + if (fFocusElement != null) { + treeViewer.setSelection(new StructuredSelection(fFocusElement), true); + } + treeViewer.addCheckStateListener(new ICheckStateListener() { + + public void checkStateChanged(CheckStateChangedEvent event) { + forceExistingChecked(event); + } + }); + + applyDialogFont(composite); + return composite; + } + + protected void forceExistingChecked(CheckStateChangedEvent event) { + if (fExisting != null) { + Object elem = event.getElement(); + if (fExisting.contains(elem)) { + fViewer.setChecked(elem, true); + } + } + } + + private void updateNewFolderButtonState() { + IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); + fSelectedContainer = null; + if (selection.size() == 1) { + Object first = selection.getFirstElement(); + if (first instanceof IContainer) { + fSelectedContainer = (IContainer) first; + } + } + fNewFolderButton.setEnabled(fSelectedContainer != null); + } + + protected void newFolderButtonPressed() { + NewFolderDialog dialog = new NewFolderDialog(getShell(), fSelectedContainer); + if (dialog.open() == Window.OK) { + CheckboxTreeViewer treeViewer = fViewer; + treeViewer.refresh(fSelectedContainer); + Object createdFolder = dialog.getResult()[0]; + treeViewer.reveal(createdFolder); + treeViewer.setChecked(createdFolder, true); + treeViewer.setSelection(new StructuredSelection(createdFolder)); + updateOKStatus(); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent event) { + updateNewFolderButtonState(); + } + + public void setInitialFocus(Object focusElement) { + fFocusElement = focusElement; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java new file mode 100644 index 00000000000..a29ddb7b669 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/dialogs/cpaths/NewSourceFolderDialog.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.dialogs.cpaths; + +import java.util.List; + +import org.eclipse.cdt.internal.ui.dialogs.StatusDialog; +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; +import org.eclipse.cdt.internal.ui.wizards.NewWizardMessages; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.DialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; +import org.eclipse.cdt.internal.ui.wizards.dialogfields.StringDialogField; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +public class NewSourceFolderDialog extends StatusDialog { + + private SelectionButtonDialogField fUseProjectButton; + private SelectionButtonDialogField fUseFolderButton; + + private StringDialogField fContainerDialogField; + private StatusInfo fContainerFieldStatus; + + private IContainer fFolder; + private List fExistingFolders; + private IProject fCurrProject; + + public NewSourceFolderDialog(Shell parent, String title, IProject project, List existingFolders, CPListElement entryToEdit) { + super(parent); + setTitle(title); + + fContainerFieldStatus = new StatusInfo(); + + SourceContainerAdapter adapter = new SourceContainerAdapter(); + + fUseProjectButton = new SelectionButtonDialogField(SWT.RADIO); + fUseProjectButton.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.useproject.button")); //$NON-NLS-1$ + fUseProjectButton.setDialogFieldListener(adapter); + + fUseFolderButton = new SelectionButtonDialogField(SWT.RADIO); + fUseFolderButton.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.usefolder.button")); //$NON-NLS-1$ + fUseFolderButton.setDialogFieldListener(adapter); + + fContainerDialogField = new StringDialogField(); + fContainerDialogField.setDialogFieldListener(adapter); + fContainerDialogField.setLabelText(NewWizardMessages.getString("NewSourceFolderDialog.sourcefolder.label")); //$NON-NLS-1$ + + fUseFolderButton.attachDialogField(fContainerDialogField); + + fFolder = null; + fExistingFolders = existingFolders; + fCurrProject = project; + + boolean useFolders = true; + if (entryToEdit == null) { + fContainerDialogField.setText(""); //$NON-NLS-1$ + } else { + IPath editPath = entryToEdit.getPath().removeFirstSegments(1); + fContainerDialogField.setText(editPath.toString()); + useFolders = !editPath.isEmpty(); + } + fUseFolderButton.setSelection(useFolders); + fUseProjectButton.setSelection(!useFolders); + } + + public void setMessage(String message) { + fContainerDialogField.setLabelText(message); + } + + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + + Composite inner = new Composite(composite, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.numColumns = 1; + inner.setLayout(layout); + + int widthHint = convertWidthInCharsToPixels(50); + + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = widthHint; + + if (fExistingFolders.contains(fCurrProject)) { + fContainerDialogField.doFillIntoGrid(inner, 2); + } else { + fUseProjectButton.doFillIntoGrid(inner, 1); + fUseFolderButton.doFillIntoGrid(inner, 1); + fContainerDialogField.getTextControl(inner); + + int horizontalIndent = convertWidthInCharsToPixels(3); + data.horizontalIndent = horizontalIndent; + } + Control control = fContainerDialogField.getTextControl(null); + control.setLayoutData(data); + + fContainerDialogField.postSetFocusOnDialogField(parent.getDisplay()); + applyDialogFont(composite); + return composite; + } + + // -------- SourceContainerAdapter -------- + + private class SourceContainerAdapter implements IDialogFieldListener { + + // -------- IDialogFieldListener + + public void dialogFieldChanged(DialogField field) { + doStatusLineUpdate(); + } + } + + protected void doStatusLineUpdate() { + checkIfPathValid(); + updateStatus(fContainerFieldStatus); + } + + protected void checkIfPathValid() { + fFolder = null; + IContainer folder = null; + if (fUseFolderButton.isSelected()) { + String pathStr = fContainerDialogField.getText(); + if (pathStr.length() == 0) { + fContainerFieldStatus.setError(NewWizardMessages.getString("NewSourceFolderDialog.error.enterpath")); //$NON-NLS-1$ + return; + } + IPath path = fCurrProject.getFullPath().append(pathStr); + IWorkspace workspace = fCurrProject.getWorkspace(); + + IStatus pathValidation = workspace.validatePath(path.toString(), IResource.FOLDER); + if (!pathValidation.isOK()) { + fContainerFieldStatus.setError(NewWizardMessages.getFormattedString("NewSourceFolderDialog.error.invalidpath", //$NON-NLS-1$ + pathValidation.getMessage())); + return; + } + folder = fCurrProject.getFolder(pathStr); + } else { + folder = fCurrProject; + } + if (isExisting(folder)) { + fContainerFieldStatus.setError(NewWizardMessages.getString("NewSourceFolderDialog.error.pathexists")); //$NON-NLS-1$ + return; + } + fContainerFieldStatus.setOK(); + fFolder = folder; + } + + private boolean isExisting(IContainer folder) { + return fExistingFolders.contains(folder); + } + + public IContainer getSourceFolder() { + return fFolder; + } + + /* + * @see org.eclipse.jface.window.Window#configureShell(Shell) + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + // WorkbenchHelp.setHelp(newShell, + // ICHelpContextIds.NEW_CONTAINER_DIALOG); + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties index 90a5009cc96..738c348abc5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/PreferencesMessages.properties @@ -120,7 +120,7 @@ CEditorPreferencePage.behaviorPage.printMarginColor=Print margin color CEditorPreferencePage.behaviorPage.linkedPositionColor=Linked position color CEditorPreferencePage.behaviorPage.Color=Color: CEditorPreferencePage.textFont.changeButton=C&hange... -TemplatePreferencePage.Viewer.preview=Preview: -BuildConsolePreferencePage.fieldEditors.buildConsoleLines=&Build console lines: CEditorPreferencePage.Navigation=Navigation CEditorPreferencePage.Enable_Hyperlink_Navigation=Enable Hyperlink Navigation + +TemplatePreferencePage.Viewer.preview=Preview: diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties index ad39e78b7a7..9e63eef18d8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties @@ -273,129 +273,6 @@ NewSnippetFileWizardPage.error.OnlyInJavaProject=The scrapbook page can only be NewSnippetFileWizardPage.open_error.message=Error in NewScrapbookPage -# ------- BuildPathsBlock ------- - -BuildPathsBlock.tab.source=&Source -BuildPathsBlock.tab.projects=&Projects -BuildPathsBlock.tab.libraries=&Libraries -BuildPathsBlock.tab.order=&Order and Export - -BuildPathsBlock.classpath.label=Build &class path order and exported entries:\n(Exported entries are contributed to dependent projects) - -BuildPathsBlock.classpath.up.button=&Up -BuildPathsBlock.classpath.down.button=&Down -BuildPathsBlock.classpath.checkall.button=Select &All -BuildPathsBlock.classpath.uncheckall.button=D&eselect All - -BuildPathsBlock.buildpath.label=Defaul&t output folder: -BuildPathsBlock.buildpath.button=Bro&wse... - -BuildPathsBlock.error.InvalidBuildPath=Invalid build output folder: ''{0}'' -BuildPathsBlock.error.EnterBuildPath=Build output folder must be entered. - -BuildPathsBlock.warning.EntryMissing=Build path entry is missing: {0} -BuildPathsBlock.warning.EntriesMissing={0} build path entries are missing. - -BuildPathsBlock.operationdesc_project=Creating project... -BuildPathsBlock.operationdesc_java=Setting build paths... - -BuildPathsBlock.ChooseOutputFolderDialog.title=Folder Selection -BuildPathsBlock.ChooseOutputFolderDialog.description=&Choose the folder for the build output: - -BuildPathsBlock.RemoveBinariesDialog.title=Setting Build Paths -BuildPathsBlock.RemoveBinariesDialog.description=The output folder has changed. OK to remove all generated resources from the old location ''{0}''? - -# ------- CPListLabelProvider ------- - -CPListLabelProvider.new=(new) -CPListLabelProvider.classcontainer=(class folder) -CPListLabelProvider.twopart={0} - {1} -CPListLabelProvider.willbecreated=(will be created) - - -# ------- SourceContainerWorkbookPage------- - -SourceContainerWorkbookPage.folders.label=Source folders on build pat&h: -SourceContainerWorkbookPage.folders.remove.button=&Remove -SourceContainerWorkbookPage.folders.add.button=&Add Folder... -SourceContainerWorkbookPage.folders.edit.button=&Edit... - -SourceContainerWorkbookPage.folders.check=Allow output folders for sour&ce folders. - -SourceContainerWorkbookPage.ExistingSourceFolderDialog.new.title=Source Folder Selection -SourceContainerWorkbookPage.ExistingSourceFolderDialog.new.description=&Choose source folders to be added to the build path: - -SourceContainerWorkbookPage.ExistingSourceFolderDialog.edit.title=Source Folder Selection -SourceContainerWorkbookPage.ExistingSourceFolderDialog.edit.description=&Select the source folder: - -SourceContainerWorkbookPage.NewSourceFolderDialog.new.title=New Source Folder -SourceContainerWorkbookPage.NewSourceFolderDialog.edit.title=Edit Source Folder - -SourceContainerWorkbookPage.NewSourceFolderDialog.description=&Enter a path relative to ''{0}'': - -SourceContainerWorkbookPage.ChangeOutputLocationDialog.title=Source Folder Added -SourceContainerWorkbookPage.ChangeOutputLocationDialog.project_and_output.message=Do you want to remove the project as source folder and update build output folder to ''{0}''? -SourceContainerWorkbookPage.ChangeOutputLocationDialog.project.message=Do you want to remove the project as source folder? - -SourceContainerWorkbookPage.exclusion_added.title=Source Folder Added -SourceContainerWorkbookPage.exclusion_added.message=Exclusion filters have been added to nesting folders. - -# ------- ProjectsWorkbookPage------- - -ProjectsWorkbookPage.projects.label=&Required projects on the build path: -ProjectsWorkbookPage.projects.checkall.button=Select &All -ProjectsWorkbookPage.projects.uncheckall.button=&Deselect All - -# ------- LibrariesWorkbookPage------- - -LibrariesWorkbookPage.libraries.label=JARs &and class folders on the build path: -LibrariesWorkbookPage.libraries.remove.button=&Remove - -LibrariesWorkbookPage.libraries.addjar.button=Add &JARs... -LibrariesWorkbookPage.libraries.addextjar.button=Add E&xternal JARs... -LibrariesWorkbookPage.libraries.addvariable.button=Add &Variable... -LibrariesWorkbookPage.libraries.addlibrary.button=Add Li&brary... -LibrariesWorkbookPage.libraries.addclassfolder.button=Add Class &Folder... - - -LibrariesWorkbookPage.libraries.edit.button=&Edit... - -LibrariesWorkbookPage.ExistingClassFolderDialog.new.title=Class Folder Selection -LibrariesWorkbookPage.ExistingClassFolderDialog.new.description=&Choose class folders to be added to the build path: - -LibrariesWorkbookPage.ExistingClassFolderDialog.edit.title=Edit Class Folder -LibrariesWorkbookPage.ExistingClassFolderDialog.edit.description=&Select the class folder: - -LibrariesWorkbookPage.NewClassFolderDialog.new.title=New Class Folder -LibrariesWorkbookPage.NewClassFolderDialog.edit.title=Edit Class Folder - -LibrariesWorkbookPage.NewClassFolderDialog.description=&Enter a path relative to ''{0}'': - -LibrariesWorkbookPage.JARArchiveDialog.new.title=JAR Selection -LibrariesWorkbookPage.JARArchiveDialog.new.description=&Choose jar archives to be added to the build path: - -LibrariesWorkbookPage.JARArchiveDialog.edit.title=Edit JAR -LibrariesWorkbookPage.JARArchiveDialog.edit.description=&Select the jar archive: - -LibrariesWorkbookPage.ContainerDialog.new.title=Add Library -LibrariesWorkbookPage.ContainerDialog.edit.title=Edit Library - -LibrariesWorkbookPage.VariableSelectionDialog.new.title=New Variable Classpath Entry -LibrariesWorkbookPage.VariableSelectionDialog.edit.title=Edit Variable Entry - -LibrariesWorkbookPage.ExtJARArchiveDialog.new.title=JAR Selection - -LibrariesWorkbookPage.ExtJARArchiveDialog.edit.title=Edit JAR - -LibrariesWorkbookPage.SourceAttachmentDialog.title=Source For ''{0}'' -LibrariesWorkbookPage.JavadocPropertyDialog.title=Javadoc For ''{0}'' - -LibrariesWorkbookPage.AdvancedDialog.title=Add Classpath Entry -LibrariesWorkbookPage.AdvancedDialog.description=Select the entry to add to the classpath: -LibrariesWorkbookPage.AdvancedDialog.createfolder=Create &New Class Folder -LibrariesWorkbookPage.AdvancedDialog.addfolder=Add &Existing Class Folder -LibrariesWorkbookPage.AdvancedDialog.addcontainer=Add &Container: - # ------- NewContainerDialog------- NewContainerDialog.error.invalidpath=Invalid folder path: ''{0}'' @@ -403,6 +280,9 @@ NewContainerDialog.error.enterpath=Folder name must be entered NewContainerDialog.error.pathexists=This folder is already in the list or it is an output folder. # ------- NewSourceFolderDialog------- +NewSourceFolderDialog.useproject.button=&Project as source folder +NewSourceFolderDialog.usefolder.button=&Folder as source folder +NewSourceFolderDialog.sourcefolder.label=&Source folder name: NewSourceFolderDialog.error.invalidpath=Invalid folder path: ''{0}'' NewSourceFolderDialog.error.enterpath=Folder name must be entered. NewSourceFolderDialog.error.pathexists=The folder is already in the list. @@ -528,68 +408,10 @@ OutputLocationDialog.error.invalidpath=Invalid path: {0} OutputLocationDialog.ChooseOutputFolder.title=Folder Selection OutputLocationDialog.ChooseOutputFolder.description=&Choose the folder for the build output: -# ------- ExclusionPatternDialog ------- - -ExclusionPatternDialog.title=Source Folder Exclusion Patterns - -ExclusionPatternDialog.pattern.label=E&xclusion patterns for ''{0}'': -ExclusionPatternDialog.pattern.add=A&dd... -ExclusionPatternDialog.pattern.add.multiple=Add &Multiple... -ExclusionPatternDialog.pattern.remove=&Remove -ExclusionPatternDialog.pattern.edit=&Edit... - -ExclusionPatternDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection -ExclusionPatternDialog.ChooseExclusionPattern.description=&Choose folders or files to exclude: - -# ------- ExclusionPatternEntryDialog ------- - -ExclusionPatternEntryDialog.add.title=Add Exclusion Pattern -ExclusionPatternEntryDialog.edit.title=Edit Exclusion Pattern -ExclusionPatternEntryDialog.description=Enter a pattern for excluding files from the source folder. Allowed wildcards are '*', '?' and '**'. Examples: 'java/util/A*.java', 'java/util/', '**/Test*'. - -ExclusionPatternEntryDialog.pattern.label=E&xclusion pattern (Path relative to ''{0}''): -ExclusionPatternEntryDialog.pattern.button=Bro&wse... - -ExclusionPatternEntryDialog.error.empty=Enter a pattern. -ExclusionPatternEntryDialog.error.notrelative=Pattern must be a relative path. -ExclusionPatternEntryDialog.error.exists=Pattern already exists. - -ExclusionPatternEntryDialog.ChooseExclusionPattern.title=Exclusion Pattern Selection -ExclusionPatternEntryDialog.ChooseExclusionPattern.description=&Choose a folder or file to exclude: - -# ------- ClasspathContainerDefaultPage------- - -ClasspathContainerDefaultPage.title=Classpath Container -ClasspathContainerDefaultPage.description=Select classpath container path. First segment is the container type. - -ClasspathContainerDefaultPage.path.label=&Classpath container path: - -ClasspathContainerDefaultPage.path.error.enterpath=Enter path. -ClasspathContainerDefaultPage.path.error.invalidpath=Invalid path. -ClasspathContainerDefaultPage.path.error.needssegment=Path needs at least one segment. -ClasspathContainerDefaultPage.path.error.alreadyexists=Entry already exists. - -# ------- ClasspathContainerSelectionPage------- - -ClasspathContainerSelectionPage.title=Add Library -ClasspathContainerSelectionPage.description=Select the library type to add. - # ------- ClasspathContainerWizard------- ClasspathContainerWizard.pagecreationerror.title= Library Wizard ClasspathContainerWizard.pagecreationerror.message=Wizard page creation failed. Check log for details. - -FolderSelectionDialog.button=Create New Folder... -CPListLabelProvider.none=(None) -CPListLabelProvider.source_attachment.label=Source attachment: -CPListLabelProvider.source_attachment_root.label=Source attachment root: -CPListLabelProvider.javadoc_location.label=Javadoc location: -CPListLabelProvider.output_folder.label=Output folder: -CPListLabelProvider.default_output_folder.label=(Default output folder) -CPListLabelProvider.exclusion_filter.label=Exclusion filter: -CPListLabelProvider.exclusion_filter_separator=; -CPListLabelProvider.unknown_element.label=unknown element -NewSourceFolderDialog.useproject.button=&Project as source folder -NewSourceFolderDialog.usefolder.button=&Folder as source folder -NewSourceFolderDialog.sourcefolder.label=&Source folder name: +FolderSelectionDialog.button=Create &New Folder... +MultipleFolderSelectionDialog.button=Create &New Folder... diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedElementSelectionValidator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedElementSelectionValidator.java new file mode 100644 index 00000000000..06b08a4973d --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedElementSelectionValidator.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards; + +import java.util.Collection; + +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.jface.util.Assert; + +import org.eclipse.ui.dialogs.ISelectionStatusValidator; + +import org.eclipse.cdt.internal.ui.dialogs.StatusInfo; + +/** + * Implementation of a ISelectionValidator to validate the + * type of an element. + * Empty selections are not accepted. + */ +public class TypedElementSelectionValidator implements ISelectionStatusValidator { + + private IStatus fgErrorStatus= new StatusInfo(IStatus.ERROR, ""); //$NON-NLS-1$ + private IStatus fgOKStatus= new StatusInfo(); + + private Class[] fAcceptedTypes; + private boolean fAllowMultipleSelection; + private Collection fRejectedElements; + + /** + * @param acceptedTypes The types accepted by the validator + * @param allowMultipleSelection If set to true, the validator + * allows multiple selection. + */ + public TypedElementSelectionValidator(Class[] acceptedTypes, boolean allowMultipleSelection) { + this(acceptedTypes, allowMultipleSelection, null); + } + + /** + * @param acceptedTypes The types accepted by the validator + * @param allowMultipleSelection If set to true, the validator + * allows multiple selection. + * @param rejectedElements A list of elements that are not accepted + */ + public TypedElementSelectionValidator(Class[] acceptedTypes, boolean allowMultipleSelection, Collection rejectedElements) { + Assert.isNotNull(acceptedTypes); + fAcceptedTypes= acceptedTypes; + fAllowMultipleSelection= allowMultipleSelection; + fRejectedElements= rejectedElements; + } + + /* + * @see org.eclipse.ui.dialogs.ISelectionValidator#isValid(java.lang.Object) + */ + public IStatus validate(Object[] elements) { + if (isValid(elements)) { + return fgOKStatus; + } + return fgErrorStatus; + } + + private boolean isOfAcceptedType(Object o) { + for (int i= 0; i < fAcceptedTypes.length; i++) { + if (fAcceptedTypes[i].isInstance(o)) { + return true; + } + } + return false; + } + + private boolean isRejectedElement(Object elem) { + return (fRejectedElements != null) && fRejectedElements.contains(elem); + } + + private boolean isValid(Object[] selection) { + if (selection.length == 0) { + return false; + } + + if (!fAllowMultipleSelection && selection.length != 1) { + return false; + } + + for (int i= 0; i < selection.length; i++) { + Object o= selection[i]; + if (!isOfAcceptedType(o) || isRejectedElement(o)) { + return false; + } + } + return true; + } +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedViewerFilter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedViewerFilter.java new file mode 100644 index 00000000000..cac9ce622bb --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/TypedViewerFilter.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards; + +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; + +/** + * Viewer filter used in selection dialogs. + */ +public class TypedViewerFilter extends ViewerFilter { + + private Class[] fAcceptedTypes; + private Object[] fRejectedElements; + + /** + * Creates a filter that only allows elements of gives types. + * @param acceptedTypes The types of accepted elements + */ + public TypedViewerFilter(Class[] acceptedTypes) { + this(acceptedTypes, null); + } + + /** + * Creates a filter that only allows elements of gives types, but not from a + * list of rejected elements. + * @param acceptedTypes Accepted elements must be of this types + * @param rejectedElements Element equals to the rejected elements are + * filtered out + */ + public TypedViewerFilter(Class[] acceptedTypes, Object[] rejectedElements) { + Assert.isNotNull(acceptedTypes); + fAcceptedTypes= acceptedTypes; + fRejectedElements= rejectedElements; + } + + /** + * @see ViewerFilter#select + */ + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (fRejectedElements != null) { + for (int i= 0; i < fRejectedElements.length; i++) { + if (element.equals(fRejectedElements[i])) { + return false; + } + } + } + for (int i= 0; i < fAcceptedTypes.length; i++) { + if (fAcceptedTypes[i].isInstance(element)) { + return true; + } + } + return false; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ITreeListAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ITreeListAdapter.java new file mode 100644 index 00000000000..c5c5c6dc434 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/ITreeListAdapter.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 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 v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.dialogfields; + +import org.eclipse.swt.events.KeyEvent; + +/** + * Change listener used by TreeListDialogField + */ +public interface ITreeListAdapter { + + /** + * A button from the button bar has been pressed. + */ + void customButtonPressed(TreeListDialogField field, int index); + + /** + * The selection of the list has changed. + */ + void selectionChanged(TreeListDialogField field); + + /** + * The list has been double clicked + */ + void doubleClicked(TreeListDialogField field); + + /** + * A key has been pressed + */ + void keyPressed(TreeListDialogField field, KeyEvent event); + + Object[] getChildren(TreeListDialogField field, Object element); + + Object getParent(TreeListDialogField field, Object element); + + boolean hasChildren(TreeListDialogField field, Object element); + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/TreeListDialogField.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/TreeListDialogField.java new file mode 100644 index 00000000000..8222eed31e8 --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/TreeListDialogField.java @@ -0,0 +1,904 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. All rights reserved. This + * program and the accompanying materials are made available under the terms of + * the Common Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: QNX Software Systems - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.internal.ui.wizards.dialogfields; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Tree; + +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; + +import org.eclipse.cdt.internal.ui.util.PixelConverter; +import org.eclipse.cdt.internal.ui.util.SWTUtil; + +/** + * A list with a button bar. Typical buttons are 'Add', 'Remove', 'Up' and + * 'Down'. List model is independend of widget creation. DialogFields controls + * are: Label, List and Composite containing buttons. + */ +public class TreeListDialogField extends DialogField { + + protected TreeViewer fTree; + protected ILabelProvider fLabelProvider; + protected TreeViewerAdapter fTreeViewerAdapter; + protected List fElements; + protected ViewerSorter fViewerSorter; + + protected String[] fButtonLabels; + private Button[] fButtonControls; + + private boolean[] fButtonsEnabled; + + private int fRemoveButtonIndex; + private int fUpButtonIndex; + private int fDownButtonIndex; + + private Label fLastSeparator; + + private Tree fTreeControl; + private Composite fButtonsControl; + private ISelection fSelectionWhenEnabled; + + private ITreeListAdapter fTreeAdapter; + + private Object fParentElement; + private int fTreeExpandLevel; + + /** + * @param adapter + * Can be null. + */ + public TreeListDialogField(ITreeListAdapter adapter, String[] buttonLabels, ILabelProvider lprovider) { + super(); + fTreeAdapter = adapter; + + fLabelProvider = lprovider; + fTreeViewerAdapter = new TreeViewerAdapter(); + fParentElement = this; + + fElements = new ArrayList(10); + + fButtonLabels = buttonLabels; + if (fButtonLabels != null) { + int nButtons = fButtonLabels.length; + fButtonsEnabled = new boolean[nButtons]; + for (int i = 0; i < nButtons; i++) { + fButtonsEnabled[i] = true; + } + } + + fTree = null; + fTreeControl = null; + fButtonsControl = null; + + fRemoveButtonIndex = -1; + fUpButtonIndex = -1; + fDownButtonIndex = -1; + + fTreeExpandLevel = 0; + } + + /** + * Sets the index of the 'remove' button in the button label array passed in + * the constructor. The behaviour of the button marked as the 'remove' + * button will then behandled internally. (enable state, button invocation + * behaviour) + */ + public void setRemoveButtonIndex(int removeButtonIndex) { + Assert.isTrue(removeButtonIndex < fButtonLabels.length); + fRemoveButtonIndex = removeButtonIndex; + } + + /** + * Sets the index of the 'up' button in the button label array passed in the + * constructor. The behaviour of the button marked as the 'up' button will + * then behandled internally. (enable state, button invocation behaviour) + */ + public void setUpButtonIndex(int upButtonIndex) { + Assert.isTrue(upButtonIndex < fButtonLabels.length); + fUpButtonIndex = upButtonIndex; + } + + /** + * Sets the index of the 'down' button in the button label array passed in + * the constructor. The behaviour of the button marked as the 'down' button + * will then be handled internally. (enable state, button invocation + * behaviour) + */ + public void setDownButtonIndex(int downButtonIndex) { + Assert.isTrue(downButtonIndex < fButtonLabels.length); + fDownButtonIndex = downButtonIndex; + } + + /** + * Sets the viewerSorter. + * + * @param viewerSorter + * The viewerSorter to set + */ + public void setViewerSorter(ViewerSorter viewerSorter) { + fViewerSorter = viewerSorter; + } + + /** + * Sets the viewerSorter. + * + * @param viewerSorter + * The viewerSorter to set + */ + public void setTreeExpansionLevel(int level) { + fTreeExpandLevel = level; + if (fTree != null) { + fTree.expandToLevel(level); + } + } + + // ------ adapter communication + + private void buttonPressed(int index) { + if (!managedButtonPressed(index) && fTreeAdapter != null) { + fTreeAdapter.customButtonPressed(this, index); + } + } + + /** + * Checks if the button pressed is handled internally + * + * @return Returns true if button has been handled. + */ + protected boolean managedButtonPressed(int index) { + if (index == fRemoveButtonIndex) { + remove(); + } else if (index == fUpButtonIndex) { + up(); + } else if (index == fDownButtonIndex) { + down(); + } else { + return false; + } + return true; + } + + // ------ layout helpers + + /* + * @see DialogField#doFillIntoGrid + */ + public Control[] doFillIntoGrid(Composite parent, int nColumns) { + PixelConverter converter = new PixelConverter(parent); + + assertEnoughColumns(nColumns); + + Label label = getLabelControl(parent); + GridData gd = gridDataForLabel(1); + gd.verticalAlignment = GridData.BEGINNING; + label.setLayoutData(gd); + + Control list = getTreeControl(parent); + gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = false; + gd.verticalAlignment = GridData.FILL; + gd.grabExcessVerticalSpace = true; + gd.horizontalSpan = nColumns - 2; + gd.widthHint = converter.convertWidthInCharsToPixels(50); + gd.heightHint = converter.convertHeightInCharsToPixels(6); + + list.setLayoutData(gd); + + Composite buttons = getButtonBox(parent); + gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = false; + gd.verticalAlignment = GridData.FILL; + gd.grabExcessVerticalSpace = true; + gd.horizontalSpan = 1; + buttons.setLayoutData(gd); + + return new Control[] { label, list, buttons}; + } + + /* + * @see DialogField#getNumberOfControls + */ + public int getNumberOfControls() { + return 3; + } + + /** + * Sets the minimal width of the buttons. Must be called after widget + * creation. + */ + public void setButtonsMinWidth(int minWidth) { + if (fLastSeparator != null) { + ((GridData) fLastSeparator.getLayoutData()).widthHint = minWidth; + } + } + + // ------ ui creation + + /** + * Returns the tree control. When called the first time, the control will be + * created. + * + * @param The + * parent composite when called the first time, or null + * after. + */ + public Control getTreeControl(Composite parent) { + if (fTreeControl == null) { + assertCompositeNotNull(parent); + + fTree = createTreeViewer(parent); + + fTreeControl = (Tree) fTree.getControl(); + fTreeControl.addKeyListener(new KeyAdapter() { + + public void keyPressed(KeyEvent e) { + handleKeyPressed(e); + } + }); + fTree.setAutoExpandLevel(99); + fTree.setContentProvider(fTreeViewerAdapter); + fTree.setLabelProvider(fLabelProvider); + fTree.addSelectionChangedListener(fTreeViewerAdapter); + fTree.addDoubleClickListener(fTreeViewerAdapter); + + fTree.setInput(fParentElement); + fTree.expandToLevel(fTreeExpandLevel); + + if (fViewerSorter != null) { + fTree.setSorter(fViewerSorter); + } + + fTreeControl.setEnabled(isEnabled()); + if (fSelectionWhenEnabled != null) { + postSetSelection(fSelectionWhenEnabled); + } + } + return fTreeControl; + } + + /** + * Returns the internally used table viewer. + */ + public TreeViewer getTreeViewer() { + return fTree; + } + + /* + * Subclasses may override to specify a different style. + */ + protected int getTreeStyle() { + int style = SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL; + return style; + } + + protected TreeViewer createTreeViewer(Composite parent) { + Tree tree = new Tree(parent, getTreeStyle()); + return new TreeViewer(tree); + } + + protected Button createButton(Composite parent, String label, SelectionListener listener) { + Button button = new Button(parent, SWT.PUSH); + button.setText(label); + button.addSelectionListener(listener); + GridData gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.grabExcessHorizontalSpace = true; + gd.verticalAlignment = GridData.BEGINNING; + gd.heightHint = SWTUtil.getButtonHeigthHint(button); + gd.widthHint = SWTUtil.getButtonWidthHint(button); + + button.setLayoutData(gd); + return button; + } + + private Label createSeparator(Composite parent) { + Label separator = new Label(parent, SWT.NONE); + separator.setVisible(false); + GridData gd = new GridData(); + gd.horizontalAlignment = GridData.FILL; + gd.verticalAlignment = GridData.BEGINNING; + gd.heightHint = 4; + separator.setLayoutData(gd); + return separator; + } + + /** + * Returns the composite containing the buttons. When called the first time, + * the control will be created. + * + * @param The + * parent composite when called the first time, or null + * after. + */ + public Composite getButtonBox(Composite parent) { + if (fButtonsControl == null) { + assertCompositeNotNull(parent); + + SelectionListener listener = new SelectionListener() { + + public void widgetDefaultSelected(SelectionEvent e) { + doButtonSelected(e); + } + + public void widgetSelected(SelectionEvent e) { + doButtonSelected(e); + } + }; + + Composite contents = new Composite(parent, SWT.NULL); + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; + contents.setLayout(layout); + + if (fButtonLabels != null) { + fButtonControls = new Button[fButtonLabels.length]; + for (int i = 0; i < fButtonLabels.length; i++) { + String currLabel = fButtonLabels[i]; + if (currLabel != null) { + fButtonControls[i] = createButton(contents, currLabel, listener); + fButtonControls[i].setEnabled(isEnabled() && fButtonsEnabled[i]); + } else { + fButtonControls[i] = null; + createSeparator(contents); + } + } + } + + fLastSeparator = createSeparator(contents); + + updateButtonState(); + fButtonsControl = contents; + } + + return fButtonsControl; + } + + private void doButtonSelected(SelectionEvent e) { + if (fButtonControls != null) { + for (int i = 0; i < fButtonControls.length; i++) { + if (e.widget == fButtonControls[i]) { + buttonPressed(i); + return; + } + } + } + } + + /** + * Handles key events in the table viewer. Specifically when the delete key + * is pressed. + */ + protected void handleKeyPressed(KeyEvent event) { + if (event.character == SWT.DEL && event.stateMask == 0) { + if (fRemoveButtonIndex != -1 && isButtonEnabled(fTree.getSelection(), fRemoveButtonIndex)) { + managedButtonPressed(fRemoveButtonIndex); + return; + } + } + fTreeAdapter.keyPressed(this, event); + } + + // ------ enable / disable management + + /* + * @see DialogField#dialogFieldChanged + */ + public void dialogFieldChanged() { + super.dialogFieldChanged(); + updateButtonState(); + } + + /* + * Updates the enable state of the all buttons + */ + protected void updateButtonState() { + if (fButtonControls != null) { + ISelection sel = fTree.getSelection(); + for (int i = 0; i < fButtonControls.length; i++) { + Button button = fButtonControls[i]; + if (isOkToUse(button)) { + button.setEnabled(isButtonEnabled(sel, i)); + } + } + } + } + + protected boolean containsAttributes(List selected) { + for (int i = 0; i < selected.size(); i++) { + if (!fElements.contains(selected.get(i))) { + return true; + } + } + return false; + } + + protected boolean getManagedButtonState(ISelection sel, int index) { + List selected = getSelectedElements(); + boolean hasAttributes = containsAttributes(selected); + if (index == fRemoveButtonIndex) { + return !selected.isEmpty() && !hasAttributes; + } else if (index == fUpButtonIndex) { + return !sel.isEmpty() && !hasAttributes && canMoveUp(selected); + } else if (index == fDownButtonIndex) { + return !sel.isEmpty() && !hasAttributes && canMoveDown(selected); + } + return true; + } + + /* + * @see DialogField#updateEnableState + */ + protected void updateEnableState() { + super.updateEnableState(); + + boolean enabled = isEnabled(); + if (isOkToUse(fTreeControl)) { + if (!enabled) { + fSelectionWhenEnabled = fTree.getSelection(); + selectElements(null); + } else { + selectElements(fSelectionWhenEnabled); + fSelectionWhenEnabled = null; + } + fTreeControl.setEnabled(enabled); + } + updateButtonState(); + } + + /** + * Sets a button enabled or disabled. + */ + public void enableButton(int index, boolean enable) { + if (fButtonsEnabled != null && index < fButtonsEnabled.length) { + fButtonsEnabled[index] = enable; + updateButtonState(); + } + } + + private boolean isButtonEnabled(ISelection sel, int index) { + boolean extraState = getManagedButtonState(sel, index); + return isEnabled() && extraState && fButtonsEnabled[index]; + } + + // ------ model access + + /** + * Sets the elements shown in the list. + */ + public void setElements(List elements) { + fElements = new ArrayList(elements); + refresh(); + if (fTree != null) { + fTree.expandToLevel(fTreeExpandLevel); + } + dialogFieldChanged(); + } + + /** + * Gets the elements shown in the list. The list returned is a copy, so it + * can be modified by the user. + */ + public List getElements() { + return new ArrayList(fElements); + } + + /** + * Gets the element shown at the given index. + */ + public Object getElement(int index) { + return fElements.get(index); + } + + /** + * Gets the index of an element in the list or -1 if element is not in list. + */ + public int getIndexOfElement(Object elem) { + return fElements.indexOf(elem); + } + + /** + * Replace an element. + */ + public void replaceElement(Object oldElement, Object newElement) throws IllegalArgumentException { + int idx = fElements.indexOf(oldElement); + if (idx != -1) { + fElements.set(idx, newElement); + if (fTree != null) { + List selected = getSelectedElements(); + if (selected.remove(oldElement)) { + selected.add(newElement); + } + boolean isExpanded = fTree.getExpandedState(oldElement); + fTree.remove(oldElement); + fTree.add(fParentElement, newElement); + if (isExpanded) { + fTree.expandToLevel(newElement, fTreeExpandLevel); + } + selectElements(new StructuredSelection(selected)); + } + dialogFieldChanged(); + } else { + throw new IllegalArgumentException(); + } + } + + /** + * Adds an element at the end of the tree list. + */ + public void addElement(Object element) { + if (fElements.contains(element)) { + return; + } + fElements.add(element); + if (fTree != null) { + fTree.add(fParentElement, element); + fTree.expandToLevel(element, fTreeExpandLevel); + } + dialogFieldChanged(); + } + + /** + * Adds elements at the end of the tree list. + */ + public void addElements(List elements) { + int nElements = elements.size(); + + if (nElements > 0) { + // filter duplicated + ArrayList elementsToAdd = new ArrayList(nElements); + + for (int i = 0; i < nElements; i++) { + Object elem = elements.get(i); + if (!fElements.contains(elem)) { + elementsToAdd.add(elem); + } + } + fElements.addAll(elementsToAdd); + if (fTree != null) { + fTree.add(fParentElement, elementsToAdd.toArray()); + for (int i = 0; i < elementsToAdd.size(); i++) { + fTree.expandToLevel(elementsToAdd.get(i), fTreeExpandLevel); + } + } + dialogFieldChanged(); + } + } + + /** + * Adds an element at a position. + */ + public void insertElementAt(Object element, int index) { + if (fElements.contains(element)) { + return; + } + fElements.add(index, element); + if (fTree != null) { + fTree.add(fParentElement, element); + if (fTreeExpandLevel != -1) { + fTree.expandToLevel(element, fTreeExpandLevel); + } + } + + dialogFieldChanged(); + } + + /** + * Adds an element at a position. + */ + public void removeAllElements() { + if (fElements.size() > 0) { + fElements.clear(); + refresh(); + dialogFieldChanged(); + } + } + + /** + * Removes an element from the list. + */ + public void removeElement(Object element) throws IllegalArgumentException { + if (fElements.remove(element)) { + if (fTree != null) { + fTree.remove(element); + } + dialogFieldChanged(); + } else { + throw new IllegalArgumentException(); + } + } + + /** + * Removes elements from the list. + */ + public void removeElements(List elements) { + if (elements.size() > 0) { + fElements.removeAll(elements); + if (fTree != null) { + fTree.remove(elements.toArray()); + } + dialogFieldChanged(); + } + } + + /** + * Gets the number of elements + */ + public int getSize() { + return fElements.size(); + } + + public void selectElements(ISelection selection) { + fSelectionWhenEnabled = selection; + if (fTree != null) { + fTree.setSelection(selection, true); + } + } + + public void selectFirstElement() { + Object element = null; + if (fViewerSorter != null) { + Object[] arr = fElements.toArray(); + fViewerSorter.sort(fTree, arr); + if (arr.length > 0) { + element = arr[0]; + } + } else { + if (fElements.size() > 0) { + element = fElements.get(0); + } + } + if (element != null) { + selectElements(new StructuredSelection(element)); + } + } + + public void postSetSelection(final ISelection selection) { + if (isOkToUse(fTreeControl)) { + Display d = fTreeControl.getDisplay(); + d.asyncExec(new Runnable() { + + public void run() { + if (isOkToUse(fTreeControl)) { + selectElements(selection); + } + } + }); + } + } + + /** + * Refreshes the tree. + */ + public void refresh() { + if (fTree != null) { + fTree.refresh(); + } + } + + /** + * Refreshes the tree. + */ + public void refresh(Object element) { + if (fTree != null) { + fTree.refresh(element); + } + } + + // ------- list maintenance + + private List moveUp(List elements, List move) { + int nElements = elements.size(); + List res = new ArrayList(nElements); + Object floating = null; + for (int i = 0; i < nElements; i++) { + Object curr = elements.get(i); + if (move.contains(curr)) { + res.add(curr); + } else { + if (floating != null) { + res.add(floating); + } + floating = curr; + } + } + if (floating != null) { + res.add(floating); + } + return res; + } + + private void moveUp(List toMoveUp) { + if (toMoveUp.size() > 0) { + setElements(moveUp(fElements, toMoveUp)); + fTree.reveal(toMoveUp.get(0)); + } + } + + private void moveDown(List toMoveDown) { + if (toMoveDown.size() > 0) { + setElements(reverse(moveUp(reverse(fElements), toMoveDown))); + fTree.reveal(toMoveDown.get(toMoveDown.size() - 1)); + } + } + + private List reverse(List p) { + List reverse = new ArrayList(p.size()); + for (int i = p.size() - 1; i >= 0; i--) { + reverse.add(p.get(i)); + } + return reverse; + } + + private void remove() { + removeElements(getSelectedElements()); + } + + private void up() { + moveUp(getSelectedElements()); + } + + private void down() { + moveDown(getSelectedElements()); + } + + private boolean canMoveUp(List selectedElements) { + if (isOkToUse(fTreeControl)) { + int nSelected = selectedElements.size(); + int nElements = fElements.size(); + for (int i = 0; i < nElements && nSelected > 0; i++) { + if (!selectedElements.contains(fElements.get(i))) { + return true; + } + nSelected--; + } + } + return false; + } + + private boolean canMoveDown(List selectedElements) { + if (isOkToUse(fTreeControl)) { + int nSelected = selectedElements.size(); + for (int i = fElements.size() - 1; i >= 0 && nSelected > 0; i--) { + if (!selectedElements.contains(fElements.get(i))) { + return true; + } + nSelected--; + } + } + return false; + } + + /** + * Returns the selected elements. + */ + public List getSelectedElements() { + ArrayList result = new ArrayList(); + if (fTree != null) { + ISelection selection = fTree.getSelection(); + if (selection instanceof IStructuredSelection) { + Iterator iter = ((IStructuredSelection) selection).iterator(); + while (iter.hasNext()) { + result.add(iter.next()); + } + } + } + return result; + } + + public void expandElement(Object element, int level) { + if (fTree != null) { + fTree.expandToLevel(element, level); + } + } + + // ------- TreeViewerAdapter + + private class TreeViewerAdapter implements ITreeContentProvider, ISelectionChangedListener, IDoubleClickListener { + + private final Object[] NO_ELEMENTS = new Object[0]; + + // ------- ITreeContentProvider Interface ------------ + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // will never happen + } + + public boolean isDeleted(Object element) { + return false; + } + + public void dispose() { + } + + public Object[] getElements(Object obj) { + return fElements.toArray(); + } + + public Object[] getChildren(Object element) { + if (fTreeAdapter != null) { + return fTreeAdapter.getChildren(TreeListDialogField.this, element); + } + return NO_ELEMENTS; + } + + public Object getParent(Object element) { + if (!fElements.contains(element) && fTreeAdapter != null) { + return fTreeAdapter.getParent(TreeListDialogField.this, element); + } + return fParentElement; + } + + public boolean hasChildren(Object element) { + if (fTreeAdapter != null) { + return fTreeAdapter.hasChildren(TreeListDialogField.this, element); + } + return false; + } + + // ------- ISelectionChangedListener Interface ------------ + + public void selectionChanged(SelectionChangedEvent event) { + doListSelected(event); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) + */ + public void doubleClick(DoubleClickEvent event) { + doDoubleClick(event); + } + + } + + protected void doListSelected(SelectionChangedEvent event) { + updateButtonState(); + if (fTreeAdapter != null) { + fTreeAdapter.selectionChanged(this); + } + } + + protected void doDoubleClick(DoubleClickEvent event) { + if (fTreeAdapter != null) { + fTreeAdapter.doubleClicked(this); + } + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridData.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridData.java deleted file mode 100644 index 7d8254c884f..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridData.java +++ /dev/null @@ -1,171 +0,0 @@ -package org.eclipse.cdt.internal.ui.wizards.swt; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.swt.SWT; - -public final class MGridData { - /** - * verticalAlignment specifies how controls will be positioned - * vertically within a cell. - * - * The default value is CENTER. - * - * Possible values are: - * - * BEGINNING: Position the control at the top of the cell - * CENTER: Position the control in the vertical center of the cell - * END: Position the control at the bottom of the cell - * FILL: Resize the control to fill the cell vertically - */ - public int verticalAlignment= CENTER; - /** - * horizontalAlignment specifies how controls will be positioned - * horizontally within a cell. - * - * The default value is BEGINNING. - * - * Possible values are: - * - * BEGINNING: Position the control at the left of the cell - * CENTER: Position the control in the horizontal center of the cell - * END: Position the control at the right of the cell - * FILL: Resize the control to fill the cell horizontally - */ - public int horizontalAlignment= BEGINNING; - /** - * widthHint specifies a minimum width for the column. A value of - * SWT.DEFAULT indicates that no minimum width is specified. - * - * The default value is SWT.DEFAULT. - */ - public int widthHint= SWT.DEFAULT; - /** - * heightHint specifies a minimum height for the row. A value of - * SWT.DEFAULT indicates that no minimum height is specified. - * - * The default value is SWT.DEFAULT. - */ - public int heightHint= SWT.DEFAULT; - /** - * horizontalIndent specifies the number of pixels of indentation - * that will be placed along the left side of the cell. - * - * The default value is 0. - */ - public int horizontalIndent= 0; - /** - * horizontalSpan specifies the number of column cells that the control - * will take up. - * - * The default value is 1. - */ - public int horizontalSpan= 1; - /** - * verticalSpan specifies the number of row cells that the control - * will take up. - * - * The default value is 1. - */ - public int verticalSpan= 1; - /** - * grabExcessHorizontalSpace specifies whether the cell will be made - * wide enough to fit the remaining horizontal space. - * - * The default value is false. - */ - public boolean grabExcessHorizontalSpace= false; - /** - * grabExcessVerticalSpace specifies whether the cell will be made - * tall enough to fit the remaining vertical space. - * - * The default value is false. - */ - public boolean grabExcessVerticalSpace= false; - - - // --------- added to original GridData -------- - - /** - * if a span is defined that is also grabing, this defines the column that - * will grab the space - * - * The default value is -1, which will result in the default behavior - * (=last culumn) - */ - public int grabColumn= -1; - - /** - * If a span is defined that is also grabing, this defines the row that - * will grab - * - * The default value is -1, which will result in the default behavior - * (=last row) - */ - public int grabRow= -1; - - // Alignment constants. - public static final int BEGINNING= 1; - public static final int CENTER= 2; - public static final int END= 3; - public static final int FILL= 4; - - // Style constants - public static final int VERTICAL_ALIGN_BEGINNING= 1 << 1; - public static final int VERTICAL_ALIGN_CENTER= 1 << 2; - public static final int VERTICAL_ALIGN_END= 1 << 3; - public static final int VERTICAL_ALIGN_FILL= 1 << 4; - public static final int HORIZONTAL_ALIGN_BEGINNING= 1 << 5; - public static final int HORIZONTAL_ALIGN_CENTER= 1 << 6; - public static final int HORIZONTAL_ALIGN_END= 1 << 7; - public static final int HORIZONTAL_ALIGN_FILL= 1 << 8; - public static final int GRAB_HORIZONTAL= 1 << 9; - public static final int GRAB_VERTICAL= 1 << 10; - - // Private - int childIndex; - boolean isItemData= true; - boolean isItemData() { - return isItemData; - } - boolean isSpacerData() { - return !isItemData; - } - public MGridData(int style) { - super(); - - if ((style & VERTICAL_ALIGN_BEGINNING) != 0) - verticalAlignment= BEGINNING; - if ((style & VERTICAL_ALIGN_CENTER) != 0) - verticalAlignment= CENTER; - if ((style & VERTICAL_ALIGN_FILL) != 0) - verticalAlignment= FILL; - if ((style & VERTICAL_ALIGN_END) != 0) - verticalAlignment= END; - - if ((style & HORIZONTAL_ALIGN_BEGINNING) != 0) - horizontalAlignment= BEGINNING; - if ((style & HORIZONTAL_ALIGN_CENTER) != 0) - horizontalAlignment= CENTER; - if ((style & HORIZONTAL_ALIGN_FILL) != 0) - horizontalAlignment= FILL; - if ((style & HORIZONTAL_ALIGN_END) != 0) - horizontalAlignment= END; - - if ((style & GRAB_HORIZONTAL) != 0) - grabExcessHorizontalSpace= true; - else - grabExcessHorizontalSpace= false; - if ((style & GRAB_VERTICAL) != 0) - grabExcessVerticalSpace= true; - else - grabExcessVerticalSpace= false; - - } - public MGridData() { - super(); - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridLayout.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridLayout.java deleted file mode 100644 index 190cf77a5f0..00000000000 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/swt/MGridLayout.java +++ /dev/null @@ -1,682 +0,0 @@ -package org.eclipse.cdt.internal.ui.wizards.swt; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Vector; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Layout; - -public final class MGridLayout extends Layout { - /** - * marginWidth specifies the number of pixels of horizontal margin - * that will be placed along the left and right edges of the layout. - * - * The default value is 5. - */ - public int marginWidth= 5; - /** - * marginHeight specifies the number of pixels of vertical margin - * that will be placed along the top and bottom edges of the layout. - * - * The default value is 5. - */ - public int marginHeight= 5; - /** - * numColumns specifies the number of cell columns in the layout. - * - * The default value is 1. - */ - public int numColumns= 1; - /** - * makeColumnsEqualWidth specifies whether all columns in the layout - * will be forced to have the same width. - * - * The default value is false. - */ - public boolean makeColumnsEqualWidth= false; - /** - * horizontalSpacing specifies the number of pixels between the right - * edge of one cell and the left edge of its neighbouring cell to - * the right. - * - * The default value is 5. - */ - public int horizontalSpacing= 5; - /** - * verticalSpacing specifies the number of pixels between the bottom - * edge of one cell and the top edge of its neighbouring cell underneath. - * - * The default value is 5. - */ - public int verticalSpacing= 5; - - - // --------- added to original GridLayout -------- - - /** - * minimumWidth specifies a minimum width of this layout - * If SWT.DEFAULT is set, no minimum width is forced - * - * The default value is SWT.DEFAULT. - */ - public int minimumWidth= SWT.DEFAULT; - /** - * minimumHeight specifies a minimum height of this layout - * If SWT.DEFAULT is set, no minimum height is forced - * - * The default value is SWT.DEFAULT. - */ - public int minimumHeight= SWT.DEFAULT; - - /** - * id specifies an identifier string for this layout. - */ - public String id; - - // Private variables. Cached values used to cut down on grid calculations. - boolean initialLayout= true; - Vector grid= new Vector(); - int[] pixelColumnWidths; - int[] pixelRowHeights; - int[] expandableColumns; - int[] expandableRows; - void adjustGridDimensions(Composite composite, boolean flushCache) { - // Ensure that widgets that span more than one row or column have enough space. - for (int row= 0; row < grid.size(); row++) { - for (int column= 0; column < numColumns; column++) { - MGridData spec= ((MGridData[]) grid.elementAt(row))[column]; - if (spec.isItemData()) { - // Widgets spanning columns. - if (spec.horizontalSpan > 1) { - Control child= composite.getChildren()[spec.childIndex]; - Point extent= child.computeSize(spec.widthHint, spec.heightHint, flushCache); - - // Calculate the size of the widget's spanned columns. - int lastSpanIndex= column + spec.horizontalSpan; - int spannedSize= 0; - for (int c= column; c < lastSpanIndex; c++) { - spannedSize= spannedSize + pixelColumnWidths[c] + horizontalSpacing; - } - spannedSize= spannedSize - horizontalSpacing; - - // If the spanned columns are not large enough to display the widget, adjust the column - // sizes to account for the extra space that is needed. - if (extent.x + spec.horizontalIndent > spannedSize) { - int extraSpaceNeeded= extent.x + spec.horizontalIndent - spannedSize; - int lastColumn= column + spec.horizontalSpan - 1; - int colWidth; - if (makeColumnsEqualWidth) { - // Evenly distribute the extra space amongst all of the columns. - int columnExtra= extraSpaceNeeded / numColumns; - int columnRemainder= extraSpaceNeeded % numColumns; - for (int i= 0; i < pixelColumnWidths.length; i++) { - colWidth= pixelColumnWidths[i] + columnExtra; - pixelColumnWidths[i]= colWidth; - } - colWidth= pixelColumnWidths[lastColumn] + columnRemainder; - pixelColumnWidths[lastColumn]= colWidth; - } else { - Vector localExpandableColumns= new Vector(); - for (int i= column; i < lastColumn; i++) { - for (int j= 0; j < expandableColumns.length; j++) { - if (expandableColumns[j] == i) { - localExpandableColumns.addElement(new Integer(i)); - } - } - } - if (localExpandableColumns.size() > 0) { - // If any of the widget's columns grab excess space, allocate the space amongst those columns. - int columnExtra= extraSpaceNeeded / localExpandableColumns.size(); - int columnRemainder= extraSpaceNeeded % localExpandableColumns.size(); - for (int i= 0; i < localExpandableColumns.size(); i++) { - int expandableCol= ((Integer) localExpandableColumns.elementAt(i)).intValue(); - colWidth= pixelColumnWidths[expandableCol] + columnExtra; - pixelColumnWidths[expandableCol]= colWidth; - } - colWidth= pixelColumnWidths[lastColumn] + columnRemainder; - pixelColumnWidths[lastColumn]= colWidth; - } else { - // Add the extra space to the widget's last column if none of its columns grab excess space. - colWidth= pixelColumnWidths[lastColumn] + extraSpaceNeeded; - pixelColumnWidths[lastColumn]= colWidth; - } - } - } - } - - // Widgets spanning rows. - if (spec.verticalSpan > 1) { - Control child= composite.getChildren()[spec.childIndex]; - Point extent= child.computeSize(spec.widthHint, spec.heightHint, flushCache); - - // Calculate the size of the widget's spanned rows. - int lastSpanIndex= row + spec.verticalSpan; - int spannedSize= 0; - for (int r= row; r < lastSpanIndex; r++) { - spannedSize= spannedSize + pixelRowHeights[r] + verticalSpacing; - } - spannedSize= spannedSize - verticalSpacing; - // If the spanned rows are not large enough to display the widget, adjust the row - // sizes to account for the extra space that is needed. - if (extent.y > spannedSize) { - int extraSpaceNeeded= extent.y - spannedSize; - int lastRow= row + spec.verticalSpan - 1; - int rowHeight; - Vector localExpandableRows= new Vector(); - for (int i= row; i < lastRow; i++) { - for (int j= 0; j < expandableRows.length; j++) { - if (expandableRows[j] == i) { - localExpandableRows.addElement(new Integer(i)); - } - } - } - if (localExpandableRows.size() > 0) { - // If any of the widget's rows grab excess space, allocate the space amongst those rows. - int rowExtra= extraSpaceNeeded / localExpandableRows.size(); - int rowRemainder= extraSpaceNeeded % localExpandableRows.size(); - for (int i= 0; i < localExpandableRows.size(); i++) { - int expandableRow= ((Integer) localExpandableRows.elementAt(i)).intValue(); - rowHeight= pixelRowHeights[expandableRow] + rowExtra; - pixelRowHeights[expandableRow]= rowHeight; - } - rowHeight= pixelRowHeights[lastRow] + rowRemainder; - pixelRowHeights[lastRow]= rowHeight; - } else { - // Add the extra space to the widget's last row if no rows grab excess space. - rowHeight= pixelRowHeights[lastRow] + extraSpaceNeeded; - pixelRowHeights[lastRow]= rowHeight; - } - } - } - } - } - } - } - void calculateGridDimensions(Composite composite, boolean flushCache) { - int maxWidth, childWidth, maxHeight, childHeight; - - // - Control[] children= composite.getChildren(); - Point[] childSizes= new Point[children.length]; - pixelColumnWidths= new int[numColumns]; - pixelRowHeights= new int[grid.size()]; - - // Loop through the grid by column to get the width that each column needs to be. - // Each column will be as wide as its widest widget. - for (int column= 0; column < numColumns; column++) { - maxWidth= 0; - for (int row= 0; row < grid.size(); row++) { - MGridData spec= ((MGridData[]) grid.elementAt(row))[column]; - if (spec.isItemData()) { - Control child= children[spec.childIndex]; - childSizes[spec.childIndex]= child.computeSize(spec.widthHint, spec.heightHint, flushCache); - childWidth= childSizes[spec.childIndex].x + spec.horizontalIndent; - if (spec.horizontalSpan == 1) { - maxWidth= Math.max(maxWidth, childWidth); - } - } - } - // Cache the values for later use. - pixelColumnWidths[column]= maxWidth; - } - - // - if (makeColumnsEqualWidth) { - maxWidth= 0; - // Find the largest column size that is necessary and make each column that size. - for (int i= 0; i < numColumns; i++) { - maxWidth= Math.max(maxWidth, pixelColumnWidths[i]); - } - for (int i= 0; i < numColumns; i++) { - pixelColumnWidths[i]= maxWidth; - } - } - - // Loop through the grid by row to get the height that each row needs to be. - // Each row will be as high as its tallest widget. - for (int row= 0; row < grid.size(); row++) { - maxHeight= 0; - for (int column= 0; column < numColumns; column++) { - MGridData spec= ((MGridData[]) grid.elementAt(row))[column]; - if (spec.isItemData()) { - childHeight= childSizes[spec.childIndex].y; - if (spec.verticalSpan == 1) { - maxHeight= Math.max(maxHeight, childHeight); - } - } - } - // Cache the values for later use. - pixelRowHeights[row]= maxHeight; - } - } - void computeExpandableCells() { - // If a widget grabs excess horizontal space, the last column that the widget spans - // will be expandable. Similarly, if a widget grabs excess vertical space, the - // last row that the widget spans will be expandable. - Hashtable growColumns= new Hashtable(); - Hashtable growRows= new Hashtable(); - for (int col= 0; col < numColumns; col++) { - for (int row= 0; row < grid.size(); row++) { - MGridData spec= ((MGridData[]) grid.elementAt(row))[col]; - if (spec.grabExcessHorizontalSpace) { - if (spec.grabColumn >= 0 && spec.grabColumn < spec.horizontalSpan) { - growColumns.put(new Integer(col + spec.grabColumn), new Object()); - } else { - growColumns.put(new Integer(col + spec.horizontalSpan - 1), new Object()); - } - } - if (spec.grabExcessVerticalSpace) { - if (spec.grabRow >= 0 && spec.grabRow < spec.verticalSpan) { - growRows.put(new Integer(row + spec.grabRow), new Object()); - } else { - growRows.put(new Integer(row + spec.verticalSpan - 1), new Object()); - } - } - } - } - - // Cache the values. These values are used later during children layout. - int i= 0; - Enumeration enum= growColumns.keys(); - expandableColumns= new int[growColumns.size()]; - while (enum.hasMoreElements()) { - expandableColumns[i]= ((Integer) enum.nextElement()).intValue(); - i= i + 1; - } - i= 0; - enum= growRows.keys(); - expandableRows= new int[growRows.size()]; - while (enum.hasMoreElements()) { - expandableRows[i]= ((Integer) enum.nextElement()).intValue(); - i= i + 1; - } - } - Point computeLayoutSize(Composite composite, int wHint, int hHint, boolean flushCache) { - int totalMarginHeight, totalMarginWidth; - int totalWidth, totalHeight; - int cols, rows; - - // Initialize the grid and other cached information that help with the grid layout. - if (grid.size() == 0) { - createGrid(composite); - calculateGridDimensions(composite, flushCache); - computeExpandableCells(); - adjustGridDimensions(composite, flushCache); - } - - // - cols= numColumns; - rows= grid.size(); - totalMarginHeight= marginHeight + composite.getBorderWidth(); - totalMarginWidth= marginWidth + composite.getBorderWidth(); - - // The total width is the margin plus border width plus space between each column, - // plus the width of each column. - totalWidth= (totalMarginWidth * 2) + ((cols - 1) * horizontalSpacing); - - //Add up the width of each column. - for (int i= 0; i < pixelColumnWidths.length; i++) { - totalWidth= totalWidth + pixelColumnWidths[i]; - } - - // The total height is the margin plus border height, plus space between each row, - // plus the height of the tallest child in each row. - totalHeight= (totalMarginHeight * 2) + ((rows - 1) * verticalSpacing); - - //Add up the height of each row. - for (int i= 0; i < pixelRowHeights.length; i++) { - totalHeight= totalHeight + pixelRowHeights[i]; - } - - if (wHint != SWT.DEFAULT) { - totalWidth= wHint; - }; - if (hHint != SWT.DEFAULT) { - totalHeight= hHint; - }; - // The preferred extent is the width and height that will accomodate the grid's widgets. - return new Point(totalWidth, totalHeight); - } - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { - - if (composite.getChildren().length == 0) - return new Point(0, 0); - - // Make sure that all of the composite children have a layout spec. Do this by - // using the initialLayout flag. - if (flushCache) - initialLayout= true; - if (initialLayout) { - initializeLayoutData(composite); - initialLayout= false; - } - - if (flushCache) { - // Cause the grid and its related information to be calculated - // again. - grid.removeAllElements(); - } - - Point size= computeLayoutSize(composite, wHint, hHint, flushCache); - if (minimumWidth != SWT.DEFAULT && size.x < minimumWidth) { - size.x= minimumWidth; - } - if (minimumHeight != SWT.DEFAULT && size.y < minimumHeight) { - size.y= minimumHeight; - } - return size; - } - void createGrid(Composite composite) { - int row, column, rowFill, columnFill; - Control[] children; - MGridData spacerSpec; - - // - children= composite.getChildren(); - - // - grid.addElement(emptyRow()); - row= 0; - column= 0; - - // Loop through the children and place their associated layout specs in the - // grid. Placement occurs left to right, top to bottom (i.e., by row). - for (int i= 0; i < children.length; i++) { - // Find the first available spot in the grid. - Control child= children[i]; - MGridData spec= (MGridData) child.getLayoutData(); - while (((MGridData[]) grid.elementAt(row))[column] != null) { - column= column + 1; - if (column >= numColumns) { - row= row + 1; - column= 0; - if (row >= grid.size()) { - grid.addElement(emptyRow()); - } - } - } - // See if the place will support the widget's horizontal span. If not, go to the - // next row. - if (column + spec.horizontalSpan - 1 >= numColumns) { - grid.addElement(emptyRow()); - row= row + 1; - column= 0; - } - - // The vertical span for the item will be at least 1. If it is > 1, - // add other rows to the grid. - for (int j= 2; j <= spec.verticalSpan; j++) { - if (row + j > grid.size()) { - grid.addElement(emptyRow()); - } - } - - // Store the layout spec. Also cache the childIndex. NOTE: That we assume the children of a - // composite are maintained in the order in which they are created and added to the composite. - ((MGridData[]) grid.elementAt(row))[column]= spec; - spec.childIndex= i; - - // Put spacers in the grid to account for the item's vertical and horizontal - // span. - rowFill= spec.verticalSpan - 1; - columnFill= spec.horizontalSpan - 1; - for (int r= 1; r <= rowFill; r++) { - for (int c= 0; c < spec.horizontalSpan; c++) { - spacerSpec= new MGridData(); - spacerSpec.isItemData= false; - ((MGridData[]) grid.elementAt(row + r))[column + c]= spacerSpec; - } - } - for (int c= 1; c <= columnFill; c++) { - for (int r= 0; r < spec.verticalSpan; r++) { - spacerSpec= new MGridData(); - spacerSpec.isItemData= false; - ((MGridData[]) grid.elementAt(row + r))[column + c]= spacerSpec; - } - } - column= column + spec.horizontalSpan - 1; - } - - // Fill out empty grid cells with spacers. - for (int k= column + 1; k < numColumns; k++) { - spacerSpec= new MGridData(); - spacerSpec.isItemData= false; - ((MGridData[]) grid.elementAt(row))[k]= spacerSpec; - } - for (int k= row + 1; k < grid.size(); k++) { - spacerSpec= new MGridData(); - spacerSpec.isItemData= false; - ((MGridData[]) grid.elementAt(k))[column]= spacerSpec; - } - } - MGridData[] emptyRow() { - MGridData[] row= new MGridData[numColumns]; - for (int i= 0; i < numColumns; i++) { - row[i]= null; - } - return row; - } - void initializeLayoutData(Composite composite) { - Control[] children= composite.getChildren(); - for (int i= 0; i < children.length; i++) { - Control child= children[i]; - if (child.getLayoutData() == null) { - child.setLayoutData(new MGridData()); - } - } - } - protected void layout(Composite composite, boolean flushCache) { - //System.out.println("start layout " + id); - //new Error (). printStackTrace(); - int[] columnWidths; - int[] rowHeights; - int rowSize, rowY, columnX; - int compositeWidth, compositeHeight; - int excessHorizontal, excessVertical; - Control[] children; - if (flushCache) { - // Cause the grid and its related information to be calculated - // again. - grid.removeAllElements(); - } - children= composite.getChildren(); - if (children.length == 0) - return; - - // - Point extent= computeLayoutSize(composite, SWT.DEFAULT, SWT.DEFAULT, flushCache); - columnWidths= new int[numColumns]; - for (int i= 0; i < pixelColumnWidths.length; i++) { - columnWidths[i]= pixelColumnWidths[i]; - } - rowHeights= new int[grid.size()]; - for (int i= 0; i < pixelRowHeights.length; i++) { - rowHeights[i]= pixelRowHeights[i]; - } - int columnWidth= 0; - rowSize= Math.max(1, grid.size()); - - // - compositeWidth= extent.x; - compositeHeight= extent.y; - - // Calculate whether or not there is any extra space or not enough space due to a resize - // operation. Then allocate/deallocate the space to columns and rows that are expandable. - // If a widget grabs excess space, its last column or row will be expandable. - excessHorizontal= composite.getClientArea().width - compositeWidth; - excessVertical= composite.getClientArea().height - compositeHeight; - - // Allocate/deallocate horizontal space. - if (expandableColumns.length != 0) { - int excess, remainder, last; - int colWidth; - excess= excessHorizontal / expandableColumns.length; - remainder= excessHorizontal % expandableColumns.length; - last= 0; - for (int i= 0; i < expandableColumns.length; i++) { - int expandableCol= expandableColumns[i]; - colWidth= columnWidths[expandableCol]; - colWidth= colWidth + excess; - columnWidths[expandableCol]= colWidth; - last= Math.max(last, expandableCol); - } - colWidth= columnWidths[last]; - colWidth= colWidth + remainder; - columnWidths[last]= colWidth; - } - - // Go through all specs in each expandable column and get the maximum specified - // widthHint. Use this as the minimumWidth for the column. - for (int i= 0; i < expandableColumns.length; i++) { - int expandableCol= expandableColumns[i]; - int colWidth= columnWidths[expandableCol]; - int minWidth= 0; - for (int j= 0; j < grid.size(); j++) { - MGridData[] row= (MGridData[]) grid.elementAt(j); - MGridData spec= row[expandableCol]; - minWidth= Math.max(minWidth, spec.widthHint); - } - columnWidths[expandableCol]= Math.max(colWidth, minWidth); - } - // Allocate/deallocate vertical space. - if (expandableRows.length != 0) { - int excess, remainder, last; - int rowHeight; - excess= excessVertical / expandableRows.length; - remainder= excessVertical % expandableRows.length; - last= 0; - for (int i= 0; i < expandableRows.length; i++) { - int expandableRow= expandableRows[i]; - rowHeight= rowHeights[expandableRow]; - rowHeight= rowHeight + excess; - rowHeights[expandableRow]= rowHeight; - last= Math.max(last, expandableRow); - } - rowHeight= rowHeights[last]; - rowHeight= rowHeight + remainder; - rowHeights[last]= rowHeight; - } - // Go through all specs in each expandable row and get the maximum specified - // heightHint. Use this as the minimumHeight for the row. - for (int i= 0; i < expandableRows.length; i++) { - int expandableRow= expandableRows[i]; - int rowHeight= rowHeights[expandableRow]; - int minHeight= 0; - MGridData[] row= (MGridData[]) grid.elementAt(expandableRow); - for (int j= 0; j < numColumns; j++) { - MGridData spec= row[j]; - minHeight= Math.max(minHeight, spec.heightHint); - } - rowHeights[expandableRow]= Math.max(rowHeight, minHeight); - } - - // Get the starting x and y. - columnX= marginWidth + composite.getBorderWidth() + composite.getClientArea().x; - rowY= marginHeight + composite.getBorderWidth() + composite.getClientArea().y; - - // Layout the widget left to right, top to bottom. - for (int r= 0; r < rowSize; r++) { - int rowHeight= rowHeights[r]; - MGridData[] row= (MGridData[]) grid.elementAt(r); - - // - for (int c= 0; c < row.length; c++) { - int spannedWidth= 0, spannedHeight= 0; - int hAlign= 0, vAlign= 0; - int widgetX= 0, widgetY= 0; - int widgetW= 0, widgetH= 0; - - // - MGridData spec= (MGridData) row[c]; - if (makeColumnsEqualWidth) { - columnWidth= composite.getBounds().width - ((marginWidth + composite.getBorderWidth()) * 2) - ((numColumns - 1) * horizontalSpacing); - columnWidth= columnWidth / numColumns; - for (int i= 0; i < columnWidths.length; i++) { - columnWidths[i]= columnWidth; - } - } else { - columnWidth= columnWidths[c]; - } - - // - spannedWidth= columnWidth; - for (int k= 1; k < spec.horizontalSpan; k++) { - if ((c + k) <= numColumns) { - if (!makeColumnsEqualWidth) { - columnWidth= columnWidths[c + k]; - } - spannedWidth= spannedWidth + columnWidth + horizontalSpacing; - } - } - - // - spannedHeight= rowHeight; - for (int k= 1; k < spec.verticalSpan; k++) { - if ((r + k) <= grid.size()) { - spannedHeight= spannedHeight + rowHeights[r + k] + verticalSpacing; - } - } - - // - if (spec.isItemData()) { - Control child= children[spec.childIndex]; - Point childExtent= child.computeSize(spec.widthHint, spec.heightHint, flushCache); - hAlign= spec.horizontalAlignment; - widgetX= columnX; - - // Calculate the x and width values for the widget. - if (hAlign == MGridData.CENTER) { - widgetX= widgetX + (spannedWidth / 2) - (childExtent.x / 2); - } else if (hAlign == MGridData.END) { - widgetX= widgetX + spannedWidth - childExtent.x - spec.horizontalIndent; - } else { - widgetX= widgetX + spec.horizontalIndent; - } - if (hAlign == MGridData.FILL) { - widgetW= spannedWidth - spec.horizontalIndent; - widgetX= columnX + spec.horizontalIndent; - } else { - widgetW= childExtent.x; - } - - // Calculate the y and height values for the widget. - vAlign= spec.verticalAlignment; - widgetY= rowY; - if (vAlign == MGridData.CENTER) { - widgetY= widgetY + (spannedHeight / 2) - (childExtent.y / 2); - } else if (vAlign == MGridData.END) { - widgetY= widgetY + spannedHeight - childExtent.y; - } else { - //widgetY= widgetY; - } - if (vAlign == MGridData.FILL) { - widgetH= spannedHeight; - widgetY= rowY; - } else { - widgetH= childExtent.y; - } - // Place the widget. - child.setBounds(widgetX, widgetY, widgetW, widgetH); - } - // Update the starting x value. - columnX= columnX + columnWidths[c] + horizontalSpacing; - } - // Update the starting y value and since we're starting a new row, reset the starting x value. - rowY= rowY + rowHeights[r] + verticalSpacing; - columnX= marginWidth + composite.getBorderWidth() + composite.getClientArea().x; - } - //System.out.println("end layout " + id); - } - public MGridLayout() { - super(); - } -} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ReferenceBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ReferenceBlock.java index 1b94d309646..713fca87b27 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ReferenceBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/ReferenceBlock.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.ui.dialogs; import java.util.ArrayList; import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.CUIMessages; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IProject; @@ -34,6 +33,8 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.model.WorkbenchContentProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; @@ -53,7 +54,7 @@ public class ReferenceBlock extends AbstractCOptionPage { } public Image getImage() { - return CPluginImages.get(CPluginImages.IMG_OBJS_PROJECT); + return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT); } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/TabFolderOptionBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/TabFolderOptionBlock.java index cbcf7984509..7d7fc4c2a2b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/TabFolderOptionBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/TabFolderOptionBlock.java @@ -39,7 +39,7 @@ public abstract class TabFolderOptionBlock { private boolean bIsValid = true; private Label messageLabel; - private ArrayList pages; + private ArrayList pages = new ArrayList(); protected ICOptionContainer fParent; private ICOptionPage fCurrentPage; @@ -66,9 +66,6 @@ public abstract class TabFolderOptionBlock { } protected void addOptionPage(ICOptionPage page) { - if (pages == null) { - pages = new ArrayList(); - } if (!pages.contains(page)) { pages.add(page); }