3
A
回答
3
這並不簡單,因爲它看起來:
import org.apache.log4j.Logger;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IPreferencesService;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.emf.common.util.URI;
import com.google.inject.Singleton;
@Singleton
public class I18nPreferences {
private final static Logger log = Logger.getLogger(I18nPreferences.class);
public final static String I18N_QUALIFIER = "com.pany.eclipse.dsl.Dsl"; // name of the prefs file without extension
public final static String VALIDATION_IGNORE_PATTERN_KEY = "validation.ignore";
/** Get validation configuration for a resource */
public ValidationConfiguration validationConfiguration(URI uri) {
// URI looks like this:
// platform:/resource/project/src/.../file.dsl
log.debug("Search config for " + uri);
ValidationConfiguration config = new ValidationConfiguration();
IPreferencesService service = Platform.getPreferencesService();
if(null == service) {
// Probably not running under Eclipse
log.debug("No IPreferencesService");
return config;
}
String platformString = uri.toPlatformString(true);
if(null == platformString) {
// Probably not running from the Eclipse UI. Might be a unit test or something
return config;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
String s = uri.isPlatformResource() ? uri.toPlatformString(true) : uri.toString();
Path path = new Path(s);
IResource resource = workspace.getRoot().getFile(path);
IProject project = null == resource ? null : resource.getProject();
if(null == resource || null == project) {
log.debug("Can't locate project " + uri + " in workspace");
return config;
}
log.debug("Loading preferences for " + project.getName());
IScopeContext[] contexts = { new ProjectScope(resource.getProject()) };
String defaultValue = "";
String patterns = service.getString(I18N_QUALIFIER, VALIDATION_IGNORE_PATTERN_KEY, defaultValue, contexts);
log.debug("Found pattern: " + patterns);
config.setIgnoreString(patterns);
return config;
}
}
0
至少有兩種可能性:
移動驗證的用戶界面項目,並直接使用偏好。
在運行時項目中使用#isEnabled(..)創建類似ValidatorGuard的接口,其默認實現返回「true」/使用某些屬性。在您的UI項目中實現該接口,您也可以從PreferenceStore中讀取信息來決定某些驗證的啓用狀態。
相關問題
- 1. 如何訪問iphone系統首選項
- 2. 訪問Photoshop首選項
- 3. 如何在我的Maven項目中包含Xtext生成器?
- 4. 在inappsettingskit中驗證首選項
- 5. 如何從Android的Recyclerview訪問項目?
- 6. JQuery驗證:如何檢查多個選項中的項目
- 7. 我如何訪問我選擇的項目? ListBox
- 8. Android:如何更改首選項中的選定項目顏色?
- 9. 訪問EditText首選項對話框
- 10. 訪問iphone設置首選項
- 11. 訪問多個共享首選項
- 12. 如何從Java項目調用Xtext解析器/ JvmModelInferrer
- 13. 從庫項目C訪問項目類#
- 14. 我想訪問我從Red Hat機器運行的Django項目
- 15. 訪問所選項目從中繼
- 16. 如何從appdelegate訪問uitablviews選定的項目?
- 17. 訪問服務器上的設置/首選項文件
- 18. 無法使用統一首選項保留我的首選項
- 19. 如何驗證選項組中的選項按鈕,如果沒有選擇作出訪問vba
- 20. 如何在瀏覽器中訪問我的zend項目?
- 21. Eclipse Oxygen的項目結構驗證器
- 22. 如何從一個項目訪問webservice到另一個項目
- 23. 訪問項目源項目
- 24. 如何修復iPhone項目的「失敗的驗證碼驗證」?
- 25. 在我的xamarin/visualstudio項目中添加首選項片段
- 26. 如何從.net訪問高級安全選項選項卡?
- 27. Django的Facebook驗證項目
- 28. 如何選擇擁有的項目或訪問中已共享的項目2003
- 29. 驗證列表的選項
- 30. 從諾言訪問項目