715263265f1792745b0369380f267a92f21a8698
[idea/community.git] / platform / lang-api / src / com / intellij / execution / util / PathMappingTable.java
1 /*
2  * Copyright 2000-2009 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.intellij.execution.util;
18
19 import com.intellij.util.ui.ColumnInfo;
20 import com.intellij.util.ui.ListTableModel;
21 import com.intellij.util.PathMappingSettings;
22
23 final class PathMappingTable extends ListTableWithButtons<PathMappingSettings.PathMapping> {
24   @Override
25   protected ListTableModel createListModel() {
26     ColumnInfo local = new ElementsColumnInfoBase<PathMappingSettings.PathMapping>("Local path") {
27       @Override
28       public String valueOf(PathMappingSettings.PathMapping pathMapping) {
29         return pathMapping.getLocalRoot();
30       }
31
32       @Override
33       public boolean isCellEditable(PathMappingSettings.PathMapping pathMapping) {
34         return canDeleteElement(pathMapping);
35       }
36
37       @Override
38       public void setValue(PathMappingSettings.PathMapping pathMapping, String s) {
39         if (s.equals(valueOf(pathMapping))) {
40           return;
41         }
42         pathMapping.setLocalRoot(s);
43         setModified();
44       }
45
46       @Override
47       protected String getDescription(PathMappingSettings.PathMapping pathMapping) {
48         return valueOf(pathMapping);
49       }
50     };
51
52     ColumnInfo remote = new ElementsColumnInfoBase<PathMappingSettings.PathMapping>("Remote path") {
53       @Override
54       public String valueOf(PathMappingSettings.PathMapping pathMapping) {
55         return pathMapping.getRemoteRoot();
56       }
57
58       @Override
59       public boolean isCellEditable(PathMappingSettings.PathMapping pathMapping) {
60         return canDeleteElement(pathMapping);
61       }
62
63       @Override
64       public void setValue(PathMappingSettings.PathMapping pathMapping, String s) {
65         if (s.equals(valueOf(pathMapping))) {
66           return;
67         }
68         pathMapping.setRemoteRoot(s);
69         setModified();
70       }
71
72       @Override
73       protected String getDescription(PathMappingSettings.PathMapping pathMapping) {
74         return valueOf(pathMapping);
75       }
76     };
77
78     return new ListTableModel((new ColumnInfo[]{local, remote}));
79   }
80
81
82   public PathMappingSettings getPathMappingSettings() {
83     return new PathMappingSettings(getElements());
84   }
85
86   @Override
87   protected PathMappingSettings.PathMapping createElement() {
88     return new PathMappingSettings.PathMapping();
89   }
90
91   @Override
92   protected PathMappingSettings.PathMapping cloneElement(PathMappingSettings.PathMapping envVariable) {
93     return envVariable.clone();
94   }
95
96   @Override
97   protected boolean canDeleteElement(PathMappingSettings.PathMapping selection) {
98     return true;
99   }
100 }