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
.snapShooter
;
19 import com
.intellij
.openapi
.ui
.Messages
;
21 import javax
.swing
.event
.TreeModelListener
;
22 import javax
.swing
.tree
.TreeModel
;
23 import javax
.swing
.tree
.TreePath
;
24 import java
.io
.IOException
;
29 public class SnapShotTreeModel
implements TreeModel
{
30 private final SnapShotClient myClient
;
31 private final SnapShotRemoteComponent myRoot
;
33 public SnapShotTreeModel(final SnapShotClient client
) {
35 myRoot
= new SnapShotRemoteComponent(0, Object
.class.getName(), "", "Root");
38 public Object
getRoot() {
42 public Object
getChild(Object parent
, int index
) {
43 SnapShotRemoteComponent component
= (SnapShotRemoteComponent
) parent
;
44 return checkGetChildren(component
) [index
];
47 private SnapShotRemoteComponent
[] checkGetChildren(final SnapShotRemoteComponent component
) {
48 if (component
.getChildren() == null) {
50 component
.setChildren(myClient
.listChildren(component
.getId()));
52 catch (IOException e
) {
53 reportDisconnection(myClient
);
54 return new SnapShotRemoteComponent
[0];
57 return component
.getChildren();
60 private static void reportDisconnection(final SnapShotClient client
) {
61 Messages
.showMessageDialog("Disconnected from remote application", "Create Form Snapshot",
62 Messages
.getErrorIcon());
63 client
.setDisconnected();
66 public int getChildCount(Object parent
) {
67 SnapShotRemoteComponent component
= (SnapShotRemoteComponent
) parent
;
68 return checkGetChildren(component
).length
;
71 public boolean isLeaf(Object node
) {
72 SnapShotRemoteComponent component
= (SnapShotRemoteComponent
) node
;
73 return checkGetChildren(component
).length
== 0;
76 public void valueForPathChanged(TreePath path
, Object newValue
) {
79 public int getIndexOfChild(Object parent
, Object child
) {
80 SnapShotRemoteComponent component
= (SnapShotRemoteComponent
) parent
;
81 final SnapShotRemoteComponent
[] snapShotRemoteComponents
= checkGetChildren(component
);
82 for(int i
=0; i
<snapShotRemoteComponents
.length
; i
++) {
83 if (snapShotRemoteComponents
[i
] == child
) {
90 public void addTreeModelListener(TreeModelListener l
) {
91 //To change body of implemented methods use File | Settings | File Templates.
94 public void removeTreeModelListener(TreeModelListener l
) {
95 //To change body of implemented methods use File | Settings | File Templates.