1 package nl.tudelft.goal.ut2004.visualizer.util;
2
3 import java.rmi.RemoteException;
4 import java.util.ArrayList;
5 import java.util.Collection;
6
7 import nl.tudelft.goal.ut2004.visualizer.connection.EnvironmentService;
8
9 public class SelectableEnvironment {
10
11 private final EnvironmentService environment;
12
13 public SelectableEnvironment(EnvironmentService environment) {
14 this.environment = environment;
15 }
16
17 public EnvironmentService getItem() {
18 return environment;
19 }
20
21
22
23
24
25
26
27
28
29
30
31 private String simplefyID(String id) {
32
33 int index = id.lastIndexOf('/');
34
35 if (index < 0) {
36 index = id.length();
37
38 }
39 return id.substring(0, index);
40 }
41
42 @Override
43 public String toString() {
44 try {
45 return simplefyID(environment.getAgentId().getToken());
46 } catch (RemoteException e) {
47 return "Unconnected Environment";
48 }
49 }
50
51 public static Collection<SelectableEnvironment> fromCollection(
52 Collection<? extends EnvironmentService> environments) {
53
54 Collection<SelectableEnvironment> ret = new ArrayList<SelectableEnvironment>(
55 environments.size());
56
57 for (EnvironmentService env : environments) {
58 ret.add(new SelectableEnvironment(env));
59 }
60
61 return ret;
62 }
63
64 }