/*
 * 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.ide.projectView.impl;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import org.jetbrains.annotations.NonNls;

public class PsiFileUrl extends AbstractUrl {

  @NonNls private static final String ELEMENT_TYPE = "psiFile";

  public PsiFileUrl(String url, String moduleName) {
    super(url, moduleName, ELEMENT_TYPE);
  }

  public Object[] createPath(Project project) {
    final VirtualFile fileByUrl = VirtualFileManager.getInstance().findFileByUrl(url);
    if (fileByUrl == null || !fileByUrl.isValid()){
      return null;
    }
    return new Object[]{PsiManager.getInstance(project).findFile(fileByUrl)};
  }

  protected AbstractUrl createUrl(String moduleName, String url) {
      return new PsiFileUrl(url, moduleName);
  }

  public AbstractUrl createUrlByElement(Object element) {
    if (element instanceof PsiFile) {
      VirtualFile file = ((PsiFile)element).getVirtualFile();
      if (file != null){
        return new PsiFileUrl(file.getUrl(), null);
      }
    }
    return null;
  }
}

@@ -20,10 +20,10 @@
 0-20
-09
+11
  Jet
@@ -684,16 +684,66 @@
 roject;%0A
+import com.intellij.openapi.util.text.StringUtil;%0A
 import c
@@ -942,16 +942,71 @@
 onNls;%0A%0A
+/**%0A * @author anna%0A * @author Konstantin Bulenkov%0A */%0A
 public c
@@ -1043,17 +1043,16 @@
 ctUrl %7B%0A
-%0A
   @NonNl
@@ -1052,16 +1052,18 @@
  @NonNls
+%0A 
  private
@@ -1126,24 +1126,30 @@
  PsiFileUrl(
+final 
 String url, 
@@ -1150,27 +1150,8 @@
  url
-, String moduleName
 ) %7B%0A
@@ -1165,26 +1165,20 @@
 er(url, 
-moduleName
+null
 , ELEMEN
@@ -1220,16 +1220,22 @@
 atePath(
+final 
 Project 
@@ -1271,21 +1271,16 @@
 ile file
-ByUrl
  = Virtu
@@ -1339,21 +1339,16 @@
 if (file
-ByUrl
  == null
@@ -1356,21 +1356,16 @@
 %7C%7C !file
-ByUrl
 .isValid
@@ -1463,21 +1463,16 @@
 ile(file
-ByUrl
 )%7D;%0A  %7D%0A
@@ -1574,20 +1574,8 @@
 (url
-, moduleName
 );%0A 
@@ -1804,22 +1804,16 @@
 getUrl()
-, null
 );%0A     
@@ -1841,11 +1841,300 @@
 ull;%0A  %7D
+%0A%0A  @Override%0A  public boolean equals(Object o) %7B%0A    if (this == o) return true;%0A    if (o instanceof PsiFileUrl) %7B%0A     return StringUtil.equals(url, ((PsiFileUrl)o).url);%0A    %7D%0A    return false;%0A  %7D%0A%0A  @Override%0A  public int hashCode() %7B%0A    return url == null ? 0 : url.hashCode();%0A  %7D
 %0A%7D%0A

add equals/hachCode for ability to remove from Favorites