diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArchiveElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArchiveElementType.java new file mode 100644 index 000000000000..d5abb844fe8e --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/ArchiveElementType.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.elements; + +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.CompositePackagingElementType; +import com.intellij.packaging.elements.PackagingElement; +import com.intellij.packaging.impl.ui.properties.ArchiveElementPropertiesPanel; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPropertiesPanel; +import com.intellij.util.Icons; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** +* @author nik +*/ +class ArchiveElementType extends CompositePackagingElementType { + ArchiveElementType() { + super("archive", CompilerBundle.message("element.type.name.archive")); + } + + @Override + public Icon getCreateElementIcon() { + return Icons.JAR_ICON; + } + + @NotNull + @Override + public ArchivePackagingElement createEmpty(@NotNull Project project) { + return new ArchivePackagingElement(); + } + + @Override + public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull ArchivePackagingElement element, + @NotNull ArtifactEditorContext context) { + final String name = element.getArchiveFileName(); + if (name.length() >= 4 && name.charAt(name.length() - 4) == '.' && StringUtil.endsWithIgnoreCase(name, "ar")) { + return new ArchiveElementPropertiesPanel(element, context); + } + return null; + } + + public PackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement parent) { + final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, "archive", ".jar"); + final String path = Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, new FilePathValidator()); + if (path == null) return null; + return PackagingElementFactoryImpl.createDirectoryOrArchiveWithParents(path, true); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyElementType.java new file mode 100644 index 000000000000..af4bb30a93d5 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryCopyElementType.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.elements; + +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDialog; +import com.intellij.openapi.fileChooser.FileChooserFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElementType; +import com.intellij.packaging.ui.ArtifactEditorContext; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** +* @author nik +*/ +public class DirectoryCopyElementType extends PackagingElementType { + public static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png"); + + DirectoryCopyElementType() { + super("dir-copy", "Directory Content"); + } + + @Override + public Icon getCreateElementIcon() { + return COPY_OF_FOLDER_ICON; + } + + @Override + public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { + return true; + } + + @NotNull + public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, + @NotNull CompositePackagingElement parent) { + final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, true); + final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); + final VirtualFile[] files = chooser.choose(null, context.getProject()); + final List list = new ArrayList(); + for (VirtualFile file : files) { + list.add(new DirectoryCopyPackagingElement(file.getPath())); + } + return list; + } + + @NotNull + public DirectoryCopyPackagingElement createEmpty(@NotNull Project project) { + return new DirectoryCopyPackagingElement(); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryElementType.java new file mode 100644 index 000000000000..d3b9a5dd4609 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/DirectoryElementType.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.elements; + +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.util.IconLoader; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.CompositePackagingElementType; +import com.intellij.packaging.elements.PackagingElement; +import com.intellij.packaging.impl.artifacts.ArtifactUtil; +import com.intellij.packaging.impl.ui.properties.DirectoryElementPropertiesPanel; +import com.intellij.packaging.ui.ArtifactEditorContext; +import com.intellij.packaging.ui.PackagingElementPropertiesPanel; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +/** +* @author nik +*/ +class DirectoryElementType extends CompositePackagingElementType { + private static final Icon ICON = IconLoader.getIcon("/actions/newFolder.png"); + + DirectoryElementType() { + super("directory", CompilerBundle.message("element.type.name.directory")); + } + + @Override + public Icon getCreateElementIcon() { + return ICON; + } + + @NotNull + public DirectoryPackagingElement createEmpty(@NotNull Project project) { + return new DirectoryPackagingElement(); + } + + @Override + public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull DirectoryPackagingElement element, + @NotNull ArtifactEditorContext context) { + if (ArtifactUtil.isArchiveName(element.getDirectoryName())) { + return new DirectoryElementPropertiesPanel(element, context); + } + return null; + } + + public PackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement parent) { + final String initialValue = PackagingElementFactoryImpl.suggestFileName(parent, "folder", ""); + String path = Messages.showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, new FilePathValidator()); + if (path == null) return null; + return PackagingElementFactoryImpl.createDirectoryOrArchiveWithParents(path, false); + } + +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyElementType.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyElementType.java new file mode 100644 index 000000000000..675751389c75 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FileCopyElementType.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.elements; + +import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.fileChooser.FileChooserDialog; +import com.intellij.openapi.fileChooser.FileChooserFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.elements.CompositePackagingElement; +import com.intellij.packaging.elements.PackagingElementType; +import com.intellij.packaging.ui.ArtifactEditorContext; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** +* @author nik +*/ +public class FileCopyElementType extends PackagingElementType { + public static final Icon ICON = IconLoader.getIcon("/fileTypes/text.png"); + + FileCopyElementType() { + super("file-copy", "File"); + } + + @Override + public Icon getCreateElementIcon() { + return ICON; + } + + @Override + public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { + return true; + } + + @NotNull + public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, + @NotNull CompositePackagingElement parent) { + final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true); + final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); + final VirtualFile[] files = chooser.choose(null, context.getProject()); + final List list = new ArrayList(); + for (VirtualFile file : files) { + list.add(new FileCopyPackagingElement(file.getPath())); + } + return list; + } + + @NotNull + public FileCopyPackagingElement createEmpty(@NotNull Project project) { + return new FileCopyPackagingElement(); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/FilePathValidator.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FilePathValidator.java new file mode 100644 index 000000000000..c31e006c1e00 --- /dev/null +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/FilePathValidator.java @@ -0,0 +1,45 @@ +/* + * Copyright 2000-2009 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.packaging.impl.elements; + +import com.intellij.openapi.ui.InputValidator; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.util.PathUtil; + +import java.util.List; + +/** + * @author nik + */ +class FilePathValidator implements InputValidator { + public boolean checkInput(String inputString) { + final List fileNames = StringUtil.split(FileUtil.toSystemIndependentName(inputString), "/"); + if (fileNames.isEmpty()) { + return false; + } + for (String fileName : fileNames) { + if (!PathUtil.isValidFileName(fileName)) { + return false; + } + } + return true; + } + + public boolean canClose(String inputString) { + return checkInput(inputString); + } +} diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java index e4569f661bc9..53c7dcbf22d8 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/elements/PackagingElementFactoryImpl.java @@ -15,11 +15,7 @@ */ package com.intellij.packaging.impl.elements; -import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserDialog; -import com.intellij.openapi.fileChooser.FileChooserFactory; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.OrderRootType; @@ -27,27 +23,19 @@ import com.intellij.openapi.roots.impl.libraries.LibraryImpl; import com.intellij.openapi.roots.impl.libraries.LibraryTableImplUtil; import com.intellij.openapi.roots.libraries.Library; import com.intellij.openapi.roots.libraries.LibraryTable; -import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.packaging.artifacts.Artifact; import com.intellij.packaging.artifacts.ArtifactPointerManager; import com.intellij.packaging.elements.*; -import com.intellij.packaging.impl.artifacts.ArtifactUtil; -import com.intellij.packaging.impl.ui.properties.ArchiveElementPropertiesPanel; -import com.intellij.packaging.impl.ui.properties.DirectoryElementPropertiesPanel; import com.intellij.packaging.ui.ArtifactEditorContext; -import com.intellij.packaging.ui.PackagingElementPropertiesPanel; import com.intellij.util.ArrayUtil; -import com.intellij.util.Icons; import com.intellij.util.PathUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -229,7 +217,7 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { } @NotNull - private static String suggestFileName(@NotNull CompositePackagingElement parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) { + public static String suggestFileName(@NotNull CompositePackagingElement parent, @NonNls @NotNull String prefix, @NonNls @NotNull String suffix) { String name = prefix + suffix; int i = 2; while (findArchiveOrDirectoryByName(parent, name) != null) { @@ -282,144 +270,12 @@ public class PackagingElementFactoryImpl extends PackagingElementFactory { return Collections.singletonList(root); } - private static class DirectoryElementType extends CompositePackagingElementType { - private static final Icon ICON = IconLoader.getIcon("/actions/newFolder.png"); - - private DirectoryElementType() { - super("directory", CompilerBundle.message("element.type.name.directory")); - } - - @Override - public Icon getCreateElementIcon() { - return ICON; - } - - @NotNull - public DirectoryPackagingElement createEmpty(@NotNull Project project) { - return new DirectoryPackagingElement(); - } - - @Override - public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull DirectoryPackagingElement element, - @NotNull ArtifactEditorContext context) { - if (ArtifactUtil.isArchiveName(element.getDirectoryName())) { - return new DirectoryElementPropertiesPanel(element, context); - } - return null; - } - - public DirectoryPackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement parent) { - final String initialValue = suggestFileName(parent, "folder", ""); - final String name = Messages.showInputDialog(context.getProject(), "Enter directory name: ", "New Directory", null, initialValue, null); - if (name == null) return null; - return new DirectoryPackagingElement(name); - } - } - - private static class ArchiveElementType extends CompositePackagingElementType { - private ArchiveElementType() { - super("archive", CompilerBundle.message("element.type.name.archive")); - } - - @Override - public Icon getCreateElementIcon() { - return Icons.JAR_ICON; - } - - @NotNull - @Override - public ArchivePackagingElement createEmpty(@NotNull Project project) { - return new ArchivePackagingElement(); - } - - @Override - public PackagingElementPropertiesPanel createElementPropertiesPanel(@NotNull ArchivePackagingElement element, - @NotNull ArtifactEditorContext context) { - final String name = element.getArchiveFileName(); - if (name.length() >= 4 && name.charAt(name.length() - 4) == '.' && StringUtil.endsWithIgnoreCase(name, "ar")) { - return new ArchiveElementPropertiesPanel(element, context); - } - return null; - } - - public ArchivePackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement parent) { - final String initialValue = suggestFileName(parent, "archive", ".jar"); - final String name = Messages.showInputDialog(context.getProject(), "Enter archive name: ", "New Archive", null, initialValue, null); - if (name == null) return null; - return new ArchivePackagingElement(name); - } - } - - public static class FileCopyElementType extends PackagingElementType { - public static final Icon ICON = IconLoader.getIcon("/fileTypes/text.png"); - - private FileCopyElementType() { - super("file-copy", "File"); - } - - @Override - public Icon getCreateElementIcon() { - return ICON; - } - - @Override - public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { - return true; - } - - @NotNull - public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, - @NotNull CompositePackagingElement parent) { - final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, true, false, true); - final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); - final VirtualFile[] files = chooser.choose(null, context.getProject()); - final List list = new ArrayList(); - for (VirtualFile file : files) { - list.add(new FileCopyPackagingElement(file.getPath())); - } - return list; - } - - @NotNull - public FileCopyPackagingElement createEmpty(@NotNull Project project) { - return new FileCopyPackagingElement(); - } - } - - public static class DirectoryCopyElementType extends PackagingElementType { - public static final Icon COPY_OF_FOLDER_ICON = IconLoader.getIcon("/nodes/copyOfFolder.png"); - - private DirectoryCopyElementType() { - super("dir-copy", "Directory Content"); - } - - @Override - public Icon getCreateElementIcon() { - return COPY_OF_FOLDER_ICON; - } - - @Override - public boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact) { - return true; - } - - @NotNull - public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, - @NotNull CompositePackagingElement parent) { - final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, false, false, false, true); - final FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, context.getProject()); - final VirtualFile[] files = chooser.choose(null, context.getProject()); - final List list = new ArrayList(); - for (VirtualFile file : files) { - list.add(new DirectoryCopyPackagingElement(file.getPath())); - } - return list; - } - - @NotNull - public DirectoryCopyPackagingElement createEmpty(@NotNull Project project) { - return new DirectoryCopyPackagingElement(); - } + public static PackagingElement createDirectoryOrArchiveWithParents(@NotNull String path, final boolean archive) { + path = FileUtil.toSystemIndependentName(path); + final String parentPath = PathUtil.getParentPath(path); + final String fileName = PathUtil.getFileName(path); + final PackagingElement element = archive ? new ArchivePackagingElement(fileName) : new DirectoryPackagingElement(fileName); + return getInstance().createParentDirectories(parentPath, element); } private static class ArtifactRootElementType extends PackagingElementType> { diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java index c48b1b2458e2..874a16d79841 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/DirectoryCopyPresentation.java @@ -20,7 +20,7 @@ import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; +import com.intellij.packaging.impl.elements.DirectoryCopyElementType; import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.PackagingElementWeights; import com.intellij.ui.SimpleTextAttributes; @@ -56,7 +56,7 @@ public class DirectoryCopyPresentation extends PackagingElementPresentation { } public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { - presentationData.setIcons(PackagingElementFactoryImpl.DirectoryCopyElementType.COPY_OF_FOLDER_ICON); + presentationData.setIcons(DirectoryCopyElementType.COPY_OF_FOLDER_ICON); if (myFile == null || !myFile.isDirectory()) { mainAttributes = SimpleTextAttributes.ERROR_ATTRIBUTES; final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath)); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java index 621ae5fcfb63..1dffcc9986ad 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/FileCopyPresentation.java @@ -19,7 +19,7 @@ import com.intellij.ide.projectView.PresentationData; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.packaging.impl.elements.PackagingElementFactoryImpl; +import com.intellij.packaging.impl.elements.FileCopyElementType; import com.intellij.packaging.ui.ArtifactEditorContext; import com.intellij.packaging.ui.PackagingElementPresentation; import com.intellij.packaging.ui.PackagingElementWeights; @@ -65,12 +65,12 @@ public class FileCopyPresentation extends PackagingElementPresentation { public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) { if (myFile != null && !myFile.isDirectory() || myContext.isManifestFile(mySourcePath)) { - presentationData.setIcons(myFile != null ? myFile.getIcon() : PackagingElementFactoryImpl.FileCopyElementType.ICON); + presentationData.setIcons(myFile != null ? myFile.getIcon() : FileCopyElementType.ICON); presentationData.addText(myOutputFileName, mainAttributes); presentationData.addText(" (" + mySourcePath + ")", commentAttributes); } else { - presentationData.setIcons(PackagingElementFactoryImpl.FileCopyElementType.ICON); + presentationData.setIcons(FileCopyElementType.ICON); presentationData.addText(myOutputFileName, SimpleTextAttributes.ERROR_ATTRIBUTES); final VirtualFile parentFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(mySourcePath)); presentationData.addText("(" + mySourcePath + ")", diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/CompositePackagingElementType.java b/java/compiler/openapi/src/com/intellij/packaging/elements/CompositePackagingElementType.java index 861e85cb4bfb..66025980b4c4 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/CompositePackagingElementType.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/CompositePackagingElementType.java @@ -39,11 +39,11 @@ public abstract class CompositePackagingElementType parent); + protected abstract PackagingElement createComposite(@NotNull ArtifactEditorContext context, CompositePackagingElement parent); @NotNull - public List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement parent) { - final E composite = createComposite(context, parent); + public List> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, @NotNull CompositePackagingElement parent) { + final PackagingElement composite = createComposite(context, parent); return composite != null ? Collections.singletonList(composite) : Collections.emptyList(); } } diff --git a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementType.java b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementType.java index 22efed1b0247..48cc0c2af441 100644 --- a/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementType.java +++ b/java/compiler/openapi/src/com/intellij/packaging/elements/PackagingElementType.java @@ -57,8 +57,8 @@ public abstract class PackagingElementType> { public abstract boolean canCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact); @NotNull - public abstract List chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, - @NotNull CompositePackagingElement parent); + public abstract List> chooseAndCreate(@NotNull ArtifactEditorContext context, @NotNull Artifact artifact, + @NotNull CompositePackagingElement parent); @NotNull public abstract E createEmpty(@NotNull Project project); diff --git a/platform/platform-api/src/com/intellij/util/PathUtil.java b/platform/platform-api/src/com/intellij/util/PathUtil.java index 25cdb5994804..b6b50484eb12 100644 --- a/platform/platform-api/src/com/intellij/util/PathUtil.java +++ b/platform/platform-api/src/com/intellij/util/PathUtil.java @@ -29,6 +29,8 @@ import java.io.File; import java.util.StringTokenizer; public class PathUtil { + private PathUtil() { + } public static String getLocalPath(VirtualFile file) { if (file == null || !file.isValid()) { @@ -125,17 +127,30 @@ public class PathUtil { } public static String suggestFileName(final String text) { - return text.replace(' ', '_') - .replace('.', '_') - .replace(File.separatorChar, '_') - .replace('\t', '_') - .replace('\n', '_') - .replace(':', '_') - .replace('*', '_') - .replace('?', '_') - .replace('<', '_') - .replace('>', '_') - .replace('/', '_') - .replace('"', '_'); + StringBuilder result = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (!isValidFileNameChar(c) || c == '.' || Character.isWhitespace(c)) { + result.append('_'); + } + else { + result.append(c); + } + } + return result.toString(); + } + + public static boolean isValidFileName(@NotNull String fileName) { + for (int i = 0; i < fileName.length(); i++) { + if (!isValidFileNameChar(fileName.charAt(i))) { + return false; + } + } + return true; + } + + private static boolean isValidFileNameChar(char c) { + return c != '/' && c != '\\' && c != '\t' && c != '\n' && c != '\r' && c != ':' && c != ';' && c != '*' && c != '?' + && c != '"' && c != '\'' && c != '<' && c != '>'; } }