From cc842765e833e577ec3ed22f7363bc076bff4f8f Mon Sep 17 00:00:00 2001 From: nik Date: Mon, 28 Dec 2009 11:08:26 +0300 Subject: [PATCH] editor remote file improved: refresh and jump to source actions added, url field added --- .../http/JumpFromRemoteFileToLocalAction.java | 102 +++++++++++++++ .../LangRemoteFileEditorActionProvider.java | 32 +++++ .../ide/actions/OpenRemoteFileAction.java | 5 +- .../openapi/editor/impl/ContextMenuImpl.java | 3 +- .../fileEditor/impl/http/HttpFileEditor.java | 88 ++++++++++--- .../impl/http/HttpFileEditorProvider.java | 9 +- .../fileEditor/impl/http/LocalFileFinder.java | 32 +++++ .../impl/http/RefreshRemoteFileAction.java | 45 +++++++ .../http/RemoteFileEditorActionProvider.java | 33 +++++ ...oteFilePanel.form => RemoteFilePanel.form} | 69 ++++++++-- ...oteFilePanel.java => RemoteFilePanel.java} | 120 ++++++++++++++---- .../http/DefaultRemoteContentProvider.java | 3 +- .../vfs/impl/http/FileDownloadingAdapter.java | 8 +- .../impl/http/FileDownloadingListener.java | 6 +- .../vfs/impl/http/HttpFileSystemImpl.java | 11 +- .../vfs/impl/http/RemoteContentProvider.java | 2 +- .../openapi/vfs/impl/http/RemoteFileInfo.java | 89 ++++++++----- .../vfs/impl/http/RemoteFileManager.java | 15 +-- .../vfs/impl/http/RemoteFileState.java | 23 ++++ .../src/META-INF/LangExtensions.xml | 2 + .../src/META-INF/PlatformExtensionPoints.xml | 3 + 21 files changed, 591 insertions(+), 109 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/JumpFromRemoteFileToLocalAction.java create mode 100644 platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/LangRemoteFileEditorActionProvider.java create mode 100644 platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/LocalFileFinder.java create mode 100644 platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RefreshRemoteFileAction.java create mode 100644 platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFileEditorActionProvider.java rename platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/{DownloadRemoteFilePanel.form => RemoteFilePanel.form} (68%) rename platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/{DownloadRemoteFilePanel.java => RemoteFilePanel.java} (56%) create mode 100644 platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileState.java diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/JumpFromRemoteFileToLocalAction.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/JumpFromRemoteFileToLocalAction.java new file mode 100644 index 000000000000..c1a5969a8f11 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/JumpFromRemoteFileToLocalAction.java @@ -0,0 +1,102 @@ +/* + * 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.openapi.fileEditor.impl.http; + +import com.intellij.CommonBundle; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.fileEditor.OpenFileDescriptor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.util.CellAppearanceUtils; +import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.popup.PopupChooserBuilder; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; +import com.intellij.openapi.vfs.impl.http.RemoteFileState; +import com.intellij.psi.search.FilenameIndex; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.ui.ColoredListCellRenderer; +import com.intellij.util.containers.ContainerUtil; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.util.Collection; + +/** + * @author nik + */ +public class JumpFromRemoteFileToLocalAction extends AnAction { + private HttpVirtualFile myFile; + private final Project myProject; + + public JumpFromRemoteFileToLocalAction(HttpVirtualFile file, Project project) { + super("Find Local File", "", IconLoader.findIcon("/general/autoscrollToSource.png")); + myFile = file; + myProject = project; + } + + @Override + public void update(AnActionEvent e) { + final RemoteFileState state = myFile.getFileInfo().getState(); + e.getPresentation().setEnabled(state == RemoteFileState.DOWNLOADED); + } + + @Override + public void actionPerformed(AnActionEvent e) { + final String url = myFile.getUrl(); + for (LocalFileFinder finder : LocalFileFinder.EP_NAME.getExtensions()) { + final VirtualFile file = finder.findLocalFile(url, myProject); + if (file != null) { + navigateToFile(myProject, file); + } + } + + final Collection files = + FilenameIndex.getVirtualFilesByName(myProject, myFile.getName(), GlobalSearchScope.allScope(myProject)); + if (files.isEmpty()) { + Messages.showErrorDialog(myProject, "Cannot find local file for '" + url + "'", CommonBundle.getErrorTitle()); + return; + } + + if (files.size() == 1) { + navigateToFile(myProject, ContainerUtil.getFirstItem(files, null)); + } + else { + final JList list = new JList(files.toArray(new VirtualFile[files.size()])); + list.setCellRenderer(new ColoredListCellRenderer() { + @Override + protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { + CellAppearanceUtils.forVirtualFile((VirtualFile)value).customize(this); + } + }); + new PopupChooserBuilder(list) + .setTitle("Select Target File") + .setMovable(true) + .setItemChoosenCallback(new Runnable() { + public void run() { + for (Object value : list.getSelectedValues()) { + navigateToFile(myProject, (VirtualFile)value); + } + } + }).createPopup().showUnderneathOf(e.getInputEvent().getComponent()); + } + } + + private static void navigateToFile(Project project, @NotNull VirtualFile file) { + new OpenFileDescriptor(project, file).navigate(true); + } +} diff --git a/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/LangRemoteFileEditorActionProvider.java b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/LangRemoteFileEditorActionProvider.java new file mode 100644 index 000000000000..766c6e2563bb --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/fileEditor/impl/http/LangRemoteFileEditorActionProvider.java @@ -0,0 +1,32 @@ +/* + * 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.openapi.fileEditor.impl.http; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public class LangRemoteFileEditorActionProvider extends RemoteFileEditorActionProvider { + @NotNull + @Override + public AnAction[] createToolbarActions(@NotNull Project project, @NotNull HttpVirtualFile file) { + return new AnAction[] {new JumpFromRemoteFileToLocalAction(file, project)}; + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/actions/OpenRemoteFileAction.java b/platform/platform-impl/src/com/intellij/ide/actions/OpenRemoteFileAction.java index c0062276e84f..548159d1c7e6 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/OpenRemoteFileAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/OpenRemoteFileAction.java @@ -15,6 +15,7 @@ */ package com.intellij.ide.actions; +import com.intellij.CommonBundle; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; @@ -40,11 +41,11 @@ public class OpenRemoteFileAction extends AnAction implements DumbAware { public void actionPerformed(final AnActionEvent e) { Project project = e.getData(PlatformDataKeys.PROJECT); String defaultUrl = "http://localhost:8080/index.html"; - String url = Messages.showInputDialog(project, "URL", "Open Remote File", null, defaultUrl, null); + String url = Messages.showInputDialog(project, "URL:", "Open Remote File", null, defaultUrl, null); if (url != null) { VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(url); if (file == null) { - Messages.showErrorDialog(project, "Cannot find file '" + url + "'", "Cannot Open File"); + Messages.showErrorDialog(project, "Cannot find file '" + url + "'", CommonBundle.getErrorTitle()); } else { FileEditorManager.getInstance(project).openFile(file, true); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ContextMenuImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ContextMenuImpl.java index 23f8cc51db44..708f5ef2808f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/ContextMenuImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/ContextMenuImpl.java @@ -30,6 +30,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager; import com.intellij.openapi.keymap.ex.KeymapManagerEx; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -201,7 +202,7 @@ public class ContextMenuImpl extends JPanel implements Disposable { } final VirtualFile file = FileDocumentManager.getInstance().getFile(document); - return file != null && file.isValid() && file.getFileSystem() == LocalFileSystem.getInstance(); + return file != null && file.isValid() && (file.getFileSystem() == LocalFileSystem.getInstance() || file instanceof HttpVirtualFile); } private void scheduleHide() { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java index 2f8ba7ba9759..0cb520b7d42c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditor.java @@ -17,15 +17,15 @@ package com.intellij.openapi.fileEditor.impl.http; import com.intellij.codeHighlighting.BackgroundEditorHighlighter; import com.intellij.ide.structureView.StructureViewBuilder; -import com.intellij.openapi.fileEditor.FileEditor; -import com.intellij.openapi.fileEditor.FileEditorLocation; -import com.intellij.openapi.fileEditor.FileEditorState; -import com.intellij.openapi.fileEditor.FileEditorStateLevel; +import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileEditor.impl.text.TextEditorState; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Key; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; -import com.intellij.openapi.project.Project; +import com.intellij.pom.Navigatable; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.beans.PropertyChangeListener; @@ -33,22 +33,25 @@ import java.beans.PropertyChangeListener; /** * @author nik */ -public class HttpFileEditor extends UserDataHolderBase implements FileEditor { - private final HttpVirtualFile myVirtualFile; - private final DownloadRemoteFilePanel myDownloadPanel; +public class HttpFileEditor implements NavigatableFileEditor { + private final UserDataHolderBase myUserDataHolder = new UserDataHolderBase(); + private final RemoteFilePanel myPanel; public HttpFileEditor(final Project project, final HttpVirtualFile virtualFile) { - myVirtualFile = virtualFile; - myDownloadPanel = new DownloadRemoteFilePanel(project, virtualFile); + myPanel = new RemoteFilePanel(project, virtualFile); } @NotNull public JComponent getComponent() { - return myDownloadPanel.getMainPanel(); + return myPanel.getMainPanel(); } public JComponent getPreferredFocusedComponent() { - return myDownloadPanel.getMainPanel(); + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getPreferredFocusedComponent(); + } + return myPanel.getMainPanel(); } @NotNull @@ -58,10 +61,18 @@ public class HttpFileEditor extends UserDataHolderBase implements FileEditor { @NotNull public FileEditorState getState(@NotNull final FileEditorStateLevel level) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getState(level); + } return new TextEditorState(); } public void setState(@NotNull final FileEditorState state) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + textEditor.setState(state); + } } public boolean isModified() { @@ -73,32 +84,79 @@ public class HttpFileEditor extends UserDataHolderBase implements FileEditor { } public void selectNotify() { - myDownloadPanel.showNotify(); + myPanel.selectNotify(); } public void deselectNotify() { - myDownloadPanel.hideNotify(); + myPanel.deselectNotify(); } public void addPropertyChangeListener(@NotNull final PropertyChangeListener listener) { + myPanel.addPropertyChangeListener(listener); } public void removePropertyChangeListener(@NotNull final PropertyChangeListener listener) { + myPanel.removePropertyChangeListener(listener); } public BackgroundEditorHighlighter getBackgroundHighlighter() { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getBackgroundHighlighter(); + } return null; } + public boolean canNavigateTo(@NotNull Navigatable navigatable) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.canNavigateTo(navigatable); + } + return false; + } + + public void navigateTo(@NotNull Navigatable navigatable) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + textEditor.navigateTo(navigatable); + } + } + + public T getUserData(@NotNull Key key) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getUserData(key); + } + return myUserDataHolder.getUserData(key); + } + + public void putUserData(@NotNull Key key, @Nullable T value) { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + textEditor.putUserData(key, value); + } + else { + myUserDataHolder.putUserData(key, value); + } + } + public FileEditorLocation getCurrentLocation() { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getCurrentLocation(); + } return null; } public StructureViewBuilder getStructureViewBuilder() { + final TextEditor textEditor = myPanel.getFileEditor(); + if (textEditor != null) { + return textEditor.getStructureViewBuilder(); + } return null; } public void dispose() { - myDownloadPanel.dispose(); + myPanel.dispose(); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditorProvider.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditorProvider.java index dbd4ccfb0827..cfd3626b6830 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditorProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/HttpFileEditorProvider.java @@ -19,13 +19,11 @@ import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorPolicy; import com.intellij.openapi.fileEditor.FileEditorProvider; import com.intellij.openapi.fileEditor.FileEditorState; -import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; import com.intellij.openapi.fileEditor.impl.text.TextEditorState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; -import com.intellij.openapi.vfs.impl.http.RemoteFileInfo; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -39,12 +37,7 @@ public class HttpFileEditorProvider implements FileEditorProvider { @NotNull public FileEditor createEditor(@NotNull final Project project, @NotNull final VirtualFile file) { - HttpVirtualFile virtualFile = (HttpVirtualFile)file; - RemoteFileInfo remoteFileInfo = virtualFile.getFileInfo(); - if (remoteFileInfo.isDownloaded()) { - return TextEditorProvider.getInstance().createEditor(project, file); - } - return new HttpFileEditor(project, virtualFile); + return new HttpFileEditor(project, (HttpVirtualFile)file); } public void disposeEditor(@NotNull final FileEditor editor) { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/LocalFileFinder.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/LocalFileFinder.java new file mode 100644 index 000000000000..9137eb5245ab --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/LocalFileFinder.java @@ -0,0 +1,32 @@ +/* + * 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.openapi.fileEditor.impl.http; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author nik + */ +public abstract class LocalFileFinder { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.http.localFileFinder"); + + @Nullable + public abstract VirtualFile findLocalFile(@NotNull String url, @NotNull Project project); +} diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RefreshRemoteFileAction.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RefreshRemoteFileAction.java new file mode 100644 index 000000000000..385e20476c91 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RefreshRemoteFileAction.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.openapi.fileEditor.impl.http; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.util.IconLoader; +import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; +import com.intellij.openapi.vfs.impl.http.RemoteFileState; + +/** + * @author nik + */ +public class RefreshRemoteFileAction extends AnAction { + private HttpVirtualFile myFile; + + public RefreshRemoteFileAction(HttpVirtualFile file) { + super("Reload File", "", IconLoader.findIcon("/actions/sync.png")); + myFile = file; + } + + @Override + public void update(AnActionEvent e) { + final RemoteFileState state = myFile.getFileInfo().getState(); + e.getPresentation().setEnabled(state == RemoteFileState.DOWNLOADED || state == RemoteFileState.ERROR_OCCURRED); + } + + @Override + public void actionPerformed(AnActionEvent e) { + myFile.refresh(true, false); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFileEditorActionProvider.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFileEditorActionProvider.java new file mode 100644 index 000000000000..fea1479eaaf4 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFileEditorActionProvider.java @@ -0,0 +1,33 @@ +/* + * 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.openapi.fileEditor.impl.http; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; +import org.jetbrains.annotations.NotNull; + +/** + * @author nik + */ +public abstract class RemoteFileEditorActionProvider { + public static final ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.http.fileEditorActionProvider"); + + @NotNull + public abstract AnAction[] createToolbarActions(@NotNull Project project, @NotNull HttpVirtualFile file); + +} diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.form b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.form similarity index 68% rename from platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.form rename to platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.form index 85e3e579f5a7..8d0287ec077e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.form +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.form @@ -1,27 +1,22 @@ -
- - + + + - - - - - - + - - + + @@ -33,7 +28,7 @@ - + @@ -62,10 +57,15 @@ + + + + + - - + + @@ -111,8 +111,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.java b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.java similarity index 56% rename from platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.java rename to platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.java index 0c4d0ed07b4f..03152dc8b811 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/DownloadRemoteFilePanel.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/http/RemoteFilePanel.java @@ -15,34 +15,43 @@ */ package com.intellij.openapi.fileEditor.impl.http; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.fileEditor.TextEditor; +import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.impl.http.FileDownloadingListener; import com.intellij.openapi.vfs.impl.http.HttpVirtualFile; import com.intellij.openapi.vfs.impl.http.RemoteFileInfo; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.vfs.impl.http.RemoteFileState; +import com.intellij.util.EventDispatcher; +import com.intellij.util.net.HTTPProxySettingsDialog; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; -import com.intellij.util.net.HTTPProxySettingsDialog; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; /** * @author nik */ -public class DownloadRemoteFilePanel { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.http.DownloadRemoteFilePanel"); +public class RemoteFilePanel implements PropertyChangeListener { + private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.http.RemoteFilePanel"); private static final Icon ERROR_ICON = IconLoader.getIcon("/runConfigurations/configurationWarning.png"); @NonNls private static final String ERROR_CARD = "error"; @NonNls private static final String DOWNLOADING_CARD = "downloading"; + @NonNls private static final String EDITOR_CARD = "editor"; private JPanel myMainPanel; private JLabel myProgressLabel; private JProgressBar myProgressBar; @@ -51,16 +60,23 @@ public class DownloadRemoteFilePanel { private JLabel myErrorLabel; private JButton myTryAgainButton; private JButton myChangeProxySettingsButton; + private JPanel myEditorPanel; + private JTextField myUrlTextField; + private JPanel myToolbarPanel; private final Project myProject; private final HttpVirtualFile myVirtualFile; private final MergingUpdateQueue myProgressUpdatesQueue; private final MyDownloadingListener myDownloadingListener; + private final EventDispatcher myDispatcher = EventDispatcher.create(PropertyChangeListener.class); + private @Nullable TextEditor myFileEditor; - public DownloadRemoteFilePanel(final Project project, final HttpVirtualFile virtualFile) { + public RemoteFilePanel(final Project project, final HttpVirtualFile virtualFile) { myProject = project; myVirtualFile = virtualFile; myErrorLabel.setIcon(ERROR_ICON); + myUrlTextField.setText(virtualFile.getUrl()); myProgressUpdatesQueue = new MergingUpdateQueue("downloading progress updates", 300, false, myMainPanel); + initToolbar(project); final RemoteFileInfo remoteFileInfo = virtualFile.getFileInfo(); myDownloadingListener = new MyDownloadingListener(); @@ -84,17 +100,27 @@ public class DownloadRemoteFilePanel { }); showCard(DOWNLOADING_CARD); remoteFileInfo.startDownloading(); - if (remoteFileInfo.isDownloaded()) { + if (remoteFileInfo.getState() == RemoteFileState.DOWNLOADED) { switchEditor(); } else { String errorMessage = remoteFileInfo.getErrorMessage(); if (errorMessage != null) { - myDownloadingListener.errorOccured(errorMessage); + myDownloadingListener.errorOccurred(errorMessage); } } } + private void initToolbar(Project project) { + DefaultActionGroup group = new DefaultActionGroup(); + group.add(new RefreshRemoteFileAction(myVirtualFile)); + for (RemoteFileEditorActionProvider actionProvider : RemoteFileEditorActionProvider.EP_NAME.getExtensions()) { + group.addAll(actionProvider.createToolbarActions(project, myVirtualFile)); + } + final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true); + myToolbarPanel.add(actionToolbar.getComponent(), BorderLayout.CENTER); + } + private void showCard(final String name) { ((CardLayout)myContentPanel.getLayout()).show(myContentPanel, name); } @@ -103,34 +129,58 @@ public class DownloadRemoteFilePanel { LOG.debug("Switching editor..."); ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject); - fileEditorManager.closeFile(myVirtualFile); - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - //todo[nik] use ActionCallback - fileEditorManager.openFile(myVirtualFile, true); - LOG.debug("Editor for downloaded file opened."); - } - }); + final TextEditor textEditor = (TextEditor)TextEditorProvider.getInstance().createEditor(myProject, myVirtualFile); + textEditor.addPropertyChangeListener(RemoteFilePanel.this); + myEditorPanel.removeAll(); + myEditorPanel.add(textEditor.getComponent(), BorderLayout.CENTER); + myFileEditor = textEditor; + showCard(EDITOR_CARD); + LOG.debug("Editor for downloaded file opened."); } }); } + @Nullable + public TextEditor getFileEditor() { + return myFileEditor; + } + public JPanel getMainPanel() { return myMainPanel; } - public void showNotify() { + public void selectNotify() { myProgressUpdatesQueue.showNotify(); + if (myFileEditor != null) { + myFileEditor.selectNotify(); + } } - public void hideNotify() { + public void deselectNotify() { myProgressUpdatesQueue.hideNotify(); + if (myFileEditor != null) { + myFileEditor.deselectNotify(); + } } public void dispose() { myVirtualFile.getFileInfo().removeDownloadingListener(myDownloadingListener); myProgressUpdatesQueue.dispose(); + if (myFileEditor != null) { + Disposer.dispose(myFileEditor); + } + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + myDispatcher.addListener(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + myDispatcher.removeListener(listener); + } + + public void propertyChange(PropertyChangeEvent evt) { + myDispatcher.getMulticaster().propertyChange(evt); } private class MyDownloadingListener implements FileDownloadingListener { @@ -138,9 +188,35 @@ public class DownloadRemoteFilePanel { switchEditor(); } - public void errorOccured(@NotNull final String errorMessage) { - myErrorLabel.setText(errorMessage); - showCard(ERROR_CARD); + public void downloadingCancelled() { + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + if (myFileEditor != null) { + showCard(EDITOR_CARD); + } + else { + myErrorLabel.setText("Downloading cancelled"); + showCard(ERROR_CARD); + } + } + }); + } + + public void downloadingStarted() { + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + showCard(DOWNLOADING_CARD); + } + }); + } + + public void errorOccurred(@NotNull final String errorMessage) { + ApplicationManager.getApplication().invokeLater(new Runnable() { + public void run() { + myErrorLabel.setText(errorMessage); + showCard(ERROR_CARD); + } + }); } public void progressMessageChanged(final boolean indeterminate, @NotNull final String message) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/DefaultRemoteContentProvider.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/DefaultRemoteContentProvider.java index 0119a63fac69..58c275d5a60d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/DefaultRemoteContentProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/DefaultRemoteContentProvider.java @@ -81,7 +81,6 @@ public class DefaultRemoteContentProvider extends RemoteContentProvider { int count = 0; while ((len = input.read(buf)) > 0) { if (callback.isCancelled()) { - callback.errorOccured(VfsBundle.message("downloading.cancelled.message")); return; } count += len; @@ -97,7 +96,7 @@ public class DefaultRemoteContentProvider extends RemoteContentProvider { } catch (IOException e) { LOG.info(e); - callback.errorOccured(VfsBundle.message("cannot.load.remote.file", url, e.getMessage())); + callback.errorOccurred(VfsBundle.message("cannot.load.remote.file", url, e.getMessage()), false); } finally { if (input != null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingAdapter.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingAdapter.java index 45112d1e0306..ae35127de09e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingAdapter.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingAdapter.java @@ -25,7 +25,13 @@ public class FileDownloadingAdapter implements FileDownloadingListener { public void fileDownloaded(final VirtualFile localFile) { } - public void errorOccured(@NotNull final String errorMessage) { + public void errorOccurred(@NotNull final String errorMessage) { + } + + public void downloadingStarted() { + } + + public void downloadingCancelled() { } public void progressMessageChanged(final boolean indeterminate, @NotNull final String message) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingListener.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingListener.java index 8d734627ba31..ac04de59b9ca 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingListener.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/FileDownloadingListener.java @@ -25,7 +25,11 @@ public interface FileDownloadingListener { void fileDownloaded(final VirtualFile localFile); - void errorOccured(@NotNull String errorMessage); + void errorOccurred(@NotNull String errorMessage); + + void downloadingStarted(); + + void downloadingCancelled(); void progressMessageChanged(final boolean indeterminate, @NotNull String message); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/HttpFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/HttpFileSystemImpl.java index 2479abbe3c80..6d6077e18255 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/HttpFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/HttpFileSystemImpl.java @@ -42,6 +42,10 @@ public class HttpFileSystemImpl extends HttpFileSystem { myDefaultRemoteContentProvider = new DefaultRemoteContentProvider(); } + public static HttpFileSystemImpl getInstanceImpl() { + return (HttpFileSystemImpl)getInstance(); + } + public VirtualFile findFileByPath(@NotNull String path) { return findFileByPath(path, false); } @@ -49,8 +53,7 @@ public class HttpFileSystemImpl extends HttpFileSystem { public VirtualFile findFileByPath(@NotNull String path, boolean isDirectory) { try { String url = VirtualFileManager.constructUrl(PROTOCOL, path); - RemoteContentProvider provider = findContentProvider(url); - return myRemoteFileManager.getOrCreateFile(url, path, isDirectory, provider); + return myRemoteFileManager.getOrCreateFile(url, path, isDirectory); } catch (IOException e) { return null; @@ -58,7 +61,7 @@ public class HttpFileSystemImpl extends HttpFileSystem { } @NotNull - private RemoteContentProvider findContentProvider(final @NotNull String url) { + public RemoteContentProvider findContentProvider(final @NotNull String url) { for (RemoteContentProvider provider : myProviders) { if (provider.canProvideContent(url)) { return provider; @@ -68,7 +71,7 @@ public class HttpFileSystemImpl extends HttpFileSystem { } public boolean isFileDownloaded(@NotNull final VirtualFile file) { - return file instanceof HttpVirtualFile && ((HttpVirtualFile)file).getFileInfo().isDownloaded(); + return file instanceof HttpVirtualFile && ((HttpVirtualFile)file).getFileInfo().getState() == RemoteFileState.DOWNLOADED; } public void addRemoteContentProvider(@NotNull final RemoteContentProvider provider, @NotNull Disposable parentDisposable) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteContentProvider.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteContentProvider.java index 4cae591f347e..7e12941b373b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteContentProvider.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteContentProvider.java @@ -37,7 +37,7 @@ public abstract class RemoteContentProvider { public interface DownloadingCallback { void finished(@Nullable FileType fileType); - void errorOccured(@NotNull String errorMessage); + void errorOccurred(@NotNull String errorMessage, boolean cancelled); void setProgressText(@NotNull String text, boolean indeterminate); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileInfo.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileInfo.java index 5d64d7dfa2c7..3eee3b1584a0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileInfo.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileInfo.java @@ -22,6 +22,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsBundle; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; @@ -30,6 +31,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; /** * @author nik @@ -39,18 +41,18 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback private final Object myLock = new Object(); private final String myUrl; private final RemoteFileManager myManager; - private final RemoteContentProvider myContentProvider; + private @Nullable RemoteContentProvider myContentProvider; private File myLocalFile; private VirtualFile myLocalVirtualFile; - private boolean myDownloaded; + private VirtualFile myPrevLocalFile; + private RemoteFileState myState = RemoteFileState.DOWNLOADING_NOT_STARTED; private String myErrorMessage; - private volatile boolean myCancelled; + private final AtomicBoolean myCancelled = new AtomicBoolean(); private final List myListeners = new SmartList(); - public RemoteFileInfo(final @NotNull String url, final @NotNull RemoteFileManager manager, final @NotNull RemoteContentProvider provider) { + public RemoteFileInfo(final @NotNull String url, final @NotNull RemoteFileManager manager) { myUrl = url; myManager = manager; - myContentProvider = provider; } public void addDownloadingListener(@NotNull FileDownloadingListener listener) { @@ -72,8 +74,9 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback public void restartDownloading() { synchronized (myLock) { myErrorMessage = null; + myPrevLocalFile = myLocalVirtualFile; myLocalVirtualFile = null; - myDownloaded = false; + myState = RemoteFileState.DOWNLOADING_NOT_STARTED; myLocalFile = null; startDownloading(); } @@ -83,20 +86,13 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback LOG.debug("Downloading requested"); File localFile; + FileDownloadingListener[] listeners; synchronized (myLock) { - if (myDownloaded) { - LOG.debug("File already downloaded: " + myLocalVirtualFile); - return; - } - if (myErrorMessage != null) { - LOG.debug("Error occured: " + myErrorMessage); - return; - } - - if (myLocalFile != null) { - LOG.debug("Downloading in progress"); + if (myState != RemoteFileState.DOWNLOADING_NOT_STARTED) { + LOG.debug("File already downloaded: file = " + myLocalVirtualFile + ", state = " + myState); return; } + myState = RemoteFileState.DOWNLOADING_IN_PROGRESS; try { myLocalFile = myManager.getStorage().createLocalFile(myUrl); @@ -104,13 +100,20 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback } catch (IOException e) { LOG.info(e); - errorOccured(VfsBundle.message("cannot.create.local.file", e.getMessage())); + errorOccurred(VfsBundle.message("cannot.create.local.file", e.getMessage()), false); return; } - myCancelled = false; + myCancelled.set(false); localFile = myLocalFile; + listeners = myListeners.toArray(new FileDownloadingListener[myListeners.size()]); + } + for (FileDownloadingListener listener : listeners) { + listener.downloadingStarted(); } + if (myContentProvider == null) { + myContentProvider = HttpFileSystemImpl.getInstanceImpl().findContentProvider(myUrl); + } myContentProvider.saveContent(myUrl, localFile, this); } @@ -152,7 +155,8 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback FileDownloadingListener[] listeners; synchronized (myLock) { myLocalVirtualFile = localFile; - myDownloaded = true; + myPrevLocalFile = null; + myState = RemoteFileState.DOWNLOADED; myErrorMessage = null; listeners = myListeners.toArray(new FileDownloadingListener[myListeners.size()]); } @@ -162,7 +166,7 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback } public boolean isCancelled() { - return myCancelled; + return myCancelled.get(); } public String getErrorMessage() { @@ -171,16 +175,20 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback } } - public void errorOccured(@NotNull final String errorMessage) { + public void errorOccurred(@NotNull final String errorMessage, boolean cancelled) { LOG.debug("Error: " + errorMessage); FileDownloadingListener[] listeners; synchronized (myLock) { myLocalVirtualFile = null; + myPrevLocalFile = null; + myState = RemoteFileState.ERROR_OCCURRED; myErrorMessage = errorMessage; listeners = myListeners.toArray(new FileDownloadingListener[myListeners.size()]); } for (FileDownloadingListener listener : listeners) { - listener.errorOccured(errorMessage); + if (!cancelled) { + listener.errorOccurred(errorMessage); + } } } @@ -210,15 +218,29 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback } } - public boolean isDownloaded() { + public RemoteFileState getState() { synchronized (myLock) { - return myDownloaded; + return myState; } } public void cancelDownloading() { + FileDownloadingListener[] listeners; synchronized (myLock) { - myCancelled = true; + myCancelled.set(true); + if (myPrevLocalFile != null) { + myLocalVirtualFile = myPrevLocalFile; + myLocalFile = VfsUtil.virtualToIoFile(myLocalVirtualFile); + myState = RemoteFileState.DOWNLOADED; + myErrorMessage = null; + } + else { + myState = RemoteFileState.ERROR_OCCURRED; + } + listeners = myListeners.toArray(new FileDownloadingListener[myListeners.size()]); + } + for (FileDownloadingListener listener : listeners) { + listener.downloadingCancelled(); } } @@ -227,7 +249,9 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback synchronized (myLock) { localVirtualFile = myLocalVirtualFile; } - if ((localVirtualFile == null || !myContentProvider.isUpToDate(myUrl, localVirtualFile)) && myContentProvider.canProvideContent(myUrl)) { + final RemoteContentProvider contentProvider = HttpFileSystemImpl.getInstanceImpl().findContentProvider(myUrl); + if ((localVirtualFile == null || !contentProvider.equals(myContentProvider) || !contentProvider.isUpToDate(myUrl, localVirtualFile))) { + myContentProvider = contentProvider; addDownloadingListener(new MyRefreshingDownloadingListener(postRunnable)); restartDownloading(); } @@ -240,6 +264,14 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback myPostRunnable = postRunnable; } + @Override + public void downloadingCancelled() { + removeDownloadingListener(this); + if (myPostRunnable != null) { + myPostRunnable.run(); + } + } + @Override public void fileDownloaded(final VirtualFile localFile) { removeDownloadingListener(this); @@ -249,12 +281,11 @@ public class RemoteFileInfo implements RemoteContentProvider.DownloadingCallback } @Override - public void errorOccured(@NotNull final String errorMessage) { + public void errorOccurred(@NotNull final String errorMessage) { removeDownloadingListener(this); if (myPostRunnable != null) { myPostRunnable.run(); } } } - } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileManager.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileManager.java index 3304003de6b3..4600082ad765 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileManager.java @@ -15,9 +15,8 @@ */ package com.intellij.openapi.vfs.impl.http; -import com.intellij.openapi.util.Trinity; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.diagnostic.Logger; import gnu.trove.THashMap; import org.jetbrains.annotations.NotNull; @@ -28,26 +27,24 @@ import java.util.Map; * @author nik */ public class RemoteFileManager { - private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vfs.impl.http.RemoteFileManager"); private final LocalFileStorage myStorage; private final HttpFileSystemImpl myHttpFileSystem; - private final Map, VirtualFileImpl> myRemoteFiles; + private final Map, VirtualFileImpl> myRemoteFiles; public RemoteFileManager(final HttpFileSystemImpl httpFileSystem) { myHttpFileSystem = httpFileSystem; myStorage = new LocalFileStorage(); - myRemoteFiles = new THashMap, VirtualFileImpl>(); + myRemoteFiles = new THashMap, VirtualFileImpl>(); } - public synchronized VirtualFileImpl getOrCreateFile(final @NotNull String url, final @NotNull String path, final boolean directory, - final @NotNull RemoteContentProvider provider) throws IOException { - Trinity key = Trinity.create(directory, provider, url); + public synchronized VirtualFileImpl getOrCreateFile(final @NotNull String url, final @NotNull String path, final boolean directory) throws IOException { + Pair key = Pair.create(directory, url); VirtualFileImpl file = myRemoteFiles.get(key); if (file == null) { if (!directory) { - RemoteFileInfo fileInfo = new RemoteFileInfo(url, this, provider); + RemoteFileInfo fileInfo = new RemoteFileInfo(url, this); file = new VirtualFileImpl(myHttpFileSystem, path, fileInfo); fileInfo.addDownloadingListener(new MyDownloadingListener(myHttpFileSystem, file)); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileState.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileState.java new file mode 100644 index 000000000000..688a2169aa48 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/http/RemoteFileState.java @@ -0,0 +1,23 @@ +/* + * 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.openapi.vfs.impl.http; + +/** + * @author nik + */ +public enum RemoteFileState { + DOWNLOADING_NOT_STARTED, DOWNLOADING_IN_PROGRESS, DOWNLOADED, ERROR_OCCURRED +} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index fdfec4697e14..f1f4b2be2e18 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -491,6 +491,8 @@ + + + + +