Eclipseplugins
PaProject.java
1 package com.proalpha.pds.paconnector;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 import org.eclipse.core.resources.ProjectScope;
7 import org.eclipse.core.runtime.IPath;
8 import org.eclipse.core.runtime.preferences.IScopeContext;
9 import org.osgi.service.prefs.BackingStoreException;
10 import org.osgi.service.prefs.Preferences;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 
14 import com.openedge.core.runtime.IAVMClient;
15 import com.openedge.core.runtime.IAVMRuntimeListener;
16 import com.openedge.core.runtime.IPropath;
17 import com.openedge.pdt.project.OEProject;
18 import com.proalpha.pds.exception.ProALPHANotAvailableException;
19 
20 public class PaProject {
21 
22  private static final Logger logger = LoggerFactory.getLogger(PaProject.class);
23  private static final String PLUGIN_ID = Activator.getDefault().getBundle().getSymbolicName();
24 
25  private final OEProject oeProject;
26  private IAVMRuntimeListener avmRuntimeListener;
27  private String customLevel = "";
28  private String codepage;
29  private String version;
30  private IPropath propath;
31  private IPath bridgePath;
32  private boolean available;
33  private RunCommonPaProgram bridge;
34 
35  public PaProject(OEProject oeProject) {
36  this.oeProject = oeProject;
37  this.available = false;
38  this.avmRuntimeListener = new AVMRuntimeListener();
39  this.oeProject.getRuntime().addAVMRuntimeListener(avmRuntimeListener);
40  }
41 
42  public IPropath getPropath() {
43  return propath;
44  }
45 
46  public RunCommonPaProgram getBridge() {
47  return bridge;
48  }
49 
50  public void setPropath(IPropath propath) {
51  this.propath = propath;
52  }
53 
54  public IPath getBridgePath() {
55  return bridgePath;
56  }
57 
58  public void setBridgePath(IPath bridgePath) {
59  this.bridgePath = bridgePath;
60  }
61 
62  public String getCodepage() {
63  return codepage;
64  }
65 
66  public void setCodepage(String codepage) {
67  this.codepage = codepage;
68  }
69 
70  public String getVersion() {
71  return version;
72  }
73 
74  public void setVersion(String version) {
75  this.version = version;
76  }
77 
78  public boolean isAvailable() {
79  return available;
80  }
81 
82  public void setAvailable(boolean available) {
83  if (!available)
84  this.bridge = null;
85  this.available = available;
86  }
87 
88  public OEProject getOeProject() {
89  return oeProject;
90  }
91 
92  public String getCustomLevel() {
93  return customLevel;
94  }
95 
96  public void setCustomLevel(String customLevel) {
97  this.customLevel = customLevel;
98  }
99 
100  public String getName() {
101  return this.getOeProject().getProject().toString();
102  }
103 
104  @Override
105  public String toString() {
106  return "proALPHA Project: " + this.getName();
107  }
108 
114  public List<PaPreference> loadPaPrefs() {
115  IScopeContext ctxt = new ProjectScope(this.getOeProject().getProject());
116  Preferences prefs = ctxt.getNode(PLUGIN_ID);
117  List<PaPreference> paPrefs = new ArrayList<>();
118 
119  try {
120  for (String pakey : prefs.keys()) {
121  PaPreference tmpPref = new PaPreference(pakey, prefs.get(pakey, ""));
122  paPrefs.add(tmpPref);
123  }
124  return paPrefs;
125  } catch (BackingStoreException e) {
126  logger.error(e.getMessage(), e);
127  }
128 
129  return new ArrayList<>();
130 
131  }
132 
140  public boolean savePaPref(String name, String value) {
141 
142  IScopeContext ctxt = new ProjectScope(this.getOeProject().getProject());
143  Preferences prefs = ctxt.getNode(PLUGIN_ID);
144 
145  if (name == null || value == null || prefs == null)
146  return false;
147 
148  prefs.put(name, value);
149 
150  try {
151  prefs.flush();
152  } catch (BackingStoreException e) {
153  return false;
154  }
155 
156  return true;
157 
158  }
159 
160  public void dispose() {
161  if (avmRuntimeListener != null) {
162  this.oeProject.getRuntime().removeAVMRuntimeListener(avmRuntimeListener);
163  avmRuntimeListener = null;
164  }
165  }
166 
167  private class AVMRuntimeListener implements IAVMRuntimeListener {
168  public void runtimeStarted(final IAVMClient runtime) {
169  logger.info("Runtime of project {} started", PaProject.this.getName());
170  PaProject.this.setAvailable(false);
171  }
172 
173  public void runtimeStopped(final IAVMClient runtime) {
174  logger.info("Runtime of project {} stopped", PaProject.this.getName());
175  PaProject.this.setAvailable(false);
176  }
177 
178  public void runtimeShutdown(IAVMClient rutime) {
179  logger.info("Runtime of project {} shut down", PaProject.this.getName());
180  PaProject.this.setAvailable(false);
181  }
182 
183  public void runtimeInitialized(final IAVMClient runtime) {
184  logger.info("Runtime of project {} initialized", PaProject.this.getName());
185  }
186 
187  public void runtimeAvailable(IAVMClient runtime) {
188  logger.info("Runtime of project {} available", PaProject.this.getName());
189  try {
190  PaProject.this.bridge = new RunCommonPaProgram(PaProject.this);
191  } catch (ProALPHANotAvailableException e) {
192  // TODO Auto-generated catch block
193  e.printStackTrace();
194  }
195  }
196 
197  }
198 
199 }
boolean savePaPref(String name, String value)
Definition: PaProject.java:140
List< PaPreference > loadPaPrefs()
Definition: PaProject.java:114