1 11 12 package org.eclipse.pde.internal.ui.editor.cheatsheet.comp; 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 17 import org.eclipse.jface.dialogs.IMessageProvider; 18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS; 19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants; 20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup; 21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskObject; 22 import org.eclipse.pde.internal.core.util.PDETextHelper; 23 import org.eclipse.pde.internal.ui.PDEUIMessages; 24 import org.eclipse.ui.forms.widgets.Form; 25 26 30 public class CompCSGroupValidator { 31 32 private Form fForm; 33 34 private HashSet fGroups; 35 36 private String fErrorCategory; 37 38 40 43 public CompCSGroupValidator(ICompCS cheatsheet, Form form, 44 String errorCategory) { 45 fForm = form; 46 fErrorCategory = errorCategory; 47 48 fGroups = new HashSet (); 49 populateGroups(cheatsheet); 50 } 51 52 55 private void populateGroups(ICompCS cheatsheet) { 56 if (cheatsheet.getFieldTaskObject().getType() == 59 ICompCSConstants.TYPE_TASKGROUP) { 60 addGroup((ICompCSTaskGroup)cheatsheet.getFieldTaskObject()); 61 } 62 } 63 64 67 public void addGroup(ICompCSTaskGroup group) { 68 fGroups.add(group); 69 if (group.hasFieldTaskObjects() == false) { 71 return; 72 } 73 ICompCSTaskObject[] taskObjects = group.getFieldTaskObjects(); 75 for (int i = 0; i < taskObjects.length; i++) { 76 if (taskObjects[i].getType() == ICompCSConstants.TYPE_TASKGROUP) { 77 addGroup((ICompCSTaskGroup)taskObjects[i]); 78 } 79 } 80 } 81 82 85 public void removeGroup(ICompCSTaskGroup group) { 86 fGroups.remove(group); 87 if (group.hasFieldTaskObjects() == false) { 89 return; 90 } 91 ICompCSTaskObject[] taskObjects = group.getFieldTaskObjects(); 93 for (int i = 0; i < taskObjects.length; i++) { 94 if (taskObjects[i].getType() == ICompCSConstants.TYPE_TASKGROUP) { 95 removeGroup((ICompCSTaskGroup)taskObjects[i]); 96 } 97 } 98 } 99 100 103 public boolean validate() { 104 if (fGroups.isEmpty()) { 106 fForm.setMessage(null); 107 return true; 108 } 109 Iterator iterator = fGroups.iterator(); 110 while (iterator.hasNext()) { 112 ICompCSTaskGroup group = (ICompCSTaskGroup)iterator.next(); 113 if (validate(group) == false) { 114 return false; 115 } 116 } 117 fForm.setMessage(null); 118 return true; 119 } 120 121 125 private boolean validate(ICompCSTaskGroup group) { 126 if (group.getFieldTaskObjectCount() == 0) { 127 String message = '[' + 128 fErrorCategory + 129 ']' + 130 ' ' + 131 PDETextHelper.translateReadText( 132 group.getFieldName()) + 133 ':' + 134 ' ' + 135 PDEUIMessages.CompCSGroupValidator_errorChildlessGroup; 136 fForm.setMessage(message, IMessageProvider.INFORMATION); 137 return false; 138 } 139 return true; 140 } 141 142 } 143 | Popular Tags |