Eclipseplugins
pAPropertyTester.java
1 package com.proalpha.pds.ui;
2 
3 import org.eclipse.core.expressions.PropertyTester;
4 import org.eclipse.core.resources.IFile;
5 import org.eclipse.core.runtime.Platform;
6 import org.eclipse.jface.text.TextSelection;
7 import org.eclipse.jface.viewers.IStructuredSelection;
8 import org.eclipse.jface.viewers.TreeSelection;
9 
10 import com.proalpha.pds.paconnector.Activator;
11 import com.proalpha.pds.paconnector.PaProject;
12 
13 public class pAPropertyTester extends PropertyTester {
14 
15  @Override
16  public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
17  IFile file = null;
18  PaProject paProject = null;
19 
20  if (receiver instanceof TextSelection || receiver instanceof TreeSelection) {
21  paProject = Activator.getDefault().getProjectManager().getPaProjectByTextSelection();
22  }
23 
24  if (paProject == null)
25  return false;
26 
27  if (!paProject.isAvailable())
28  return false;
29 
30  file = Activator.getDefault().getProjectManager().getFileFromActiveSelection();
31 
32  if (file == null)
33  return false;
34 
35  if ("canCreateUserExit".equalsIgnoreCase(property)) {
36 
37 
38  if (paProject.getCustomLevel().isEmpty()
40  return false;
41 
42  // If file doesn't exist then allow creation
43  return !UserExitTools.userExitFileExists(file, paProject.getCustomLevel());
44  }
45 
46  else if ("canUpdateUserExit".equalsIgnoreCase(property)) {
47 
48 
49  // Check the file extension allow to create a USER EXIT
50  if (paProject.getCustomLevel().isEmpty()
52  return false;
53 
54  // Update a user-exit for a class makes no sense because there arent't any
55  // user-exit entries which need to get updated
56  if (file.getFileExtension().equals("cls"))
57  return false;
58 
59  // If file exists allow update
60  return UserExitTools.userExitFileExists(file, paProject.getCustomLevel());
61  }
62 
63  return false;
64  }
65 
66 }
static boolean userExitFileExists(IFile file, String customlevel)
static boolean userexitpossible(IFile filename)