Eclipseplugins
AddToCodeCheckedBy.java
1 package com.proalpha.pds.util;
2 
3 import java.text.SimpleDateFormat;
4 import java.util.Date;
5 import java.util.Iterator;
6 
7 import org.eclipse.jface.dialogs.MessageDialog;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.ui.PlatformUI;
11 
12 import com.openedge.pdt.project.OEProjectPlugin;
13 import com.proalpha.pds.exception.ProALPHANotAvailableException;
14 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntryRepos;
15 import com.proalpha.pds.paconnector.Activator;
16 import com.proalpha.pds.paconnector.PaProject;
17 import com.proalpha.pds.paconnector.RunProgramInPa;
18 
19 public class AddToCodeCheckedBy {
20 
21  public void add(ISelection selection, String paProjectName) {
22  Object object;
23  Iterator<?> it = ((IStructuredSelection) selection).iterator();
24 
25  while (it.hasNext()) {
26 
27  object = it.next();
28 
29  if (object instanceof TtDSLogEntryRepos) {
30  TtDSLogEntryRepos entryRepos = (TtDSLogEntryRepos) object;
31 
32  PaProject currentProject = Activator.getDefault().getProjectManager().getPaProject(
33  OEProjectPlugin.getDefault().getOpenEdgeModel().getOpenEdgeProject(paProjectName));
34 
35  if (currentProject != null && currentProject.isAvailable()) {
36  try {
37  RunProgramInPa runPaProg = new RunProgramInPa(currentProject);
38 
39  SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
40 
41  runPaProg.runSupportProcedure("ds_oea35.p", entryRepos.getOwningObj(), entryRepos.getOwningID(),
42  entryRepos.getDSCheckID(), entryRepos.getDSSubCheckID(),
43  entryRepos.getLogEntryDescription(), entryRepos.getLastUser(), "",
44  dateFormatter.format(new Date()));
45  } catch (ProALPHANotAvailableException e) {
46  displayPaNotAvailableWarning(paProjectName);
47  return;
48  }
49  } else {
50  displayPaNotAvailableWarning(paProjectName);
51  return;
52  }
53  }
54  }
55  }
56 
57  private void displayPaNotAvailableWarning(String paProjectName) {
58  MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
59  "Add to codecheckedby.xml not available",
60  "The selected project " + paProjectName + " is not open. Add to codecheckedby.xml is only "
61  + "accessible if the selected project is available.");
62  }
63 }
String runSupportProcedure(String supportProcedure, String... parameters)