2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.uiDesigner
.make
;
19 import com
.intellij
.openapi
.fileEditor
.FileEditor
;
20 import com
.intellij
.openapi
.fileEditor
.FileEditorManager
;
21 import com
.intellij
.openapi
.fileEditor
.OpenFileDescriptor
;
22 import com
.intellij
.openapi
.project
.Project
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.pom
.Navigatable
;
25 import com
.intellij
.uiDesigner
.editor
.UIFormEditor
;
26 import org
.jetbrains
.annotations
.Nullable
;
28 import java
.util
.List
;
33 public class FormElementNavigatable
implements Navigatable
{
34 private final Project myProject
;
35 private final VirtualFile myVirtualFile
;
36 private @Nullable final String myComponentId
;
38 public FormElementNavigatable(final Project project
, final VirtualFile virtualFile
, @Nullable final String componentId
) {
40 myVirtualFile
= virtualFile
;
41 myComponentId
= componentId
;
44 public void navigate(boolean requestFocus
) {
45 if (!myVirtualFile
.isValid()) return;
46 OpenFileDescriptor descriptor
= new OpenFileDescriptor(myProject
, myVirtualFile
);
47 final List
<FileEditor
> fileEditors
= FileEditorManager
.getInstance(myProject
).openEditor(descriptor
, requestFocus
);
48 if (myComponentId
!= null) {
49 for(FileEditor editor
: fileEditors
) {
50 if (editor
instanceof UIFormEditor
) {
51 ((UIFormEditor
) editor
).selectComponentById(myComponentId
);
58 public boolean canNavigate() {
59 return myVirtualFile
.isValid();
62 public boolean canNavigateToSource() {
63 return myVirtualFile
.isValid();