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. Xtext從驗證器中獲取項目根目錄
- 2. 如何訪問iphone系統首選項
- 3. 如何訪問Xtext驗證器中的本地文件系統?
- 4. 訪問Photoshop首選項
- 5. 從服務訪問共享首選項
- 6. 訪問其他活動的首選項
- 7. 如何在我的Maven項目中包含Xtext生成器?
- 8. 在inappsettingskit中驗證首選項
- 9. 如何從escript訪問項目的Mixfile?
- 10. 如何從Android的Recyclerview訪問項目?
- 11. JQuery驗證:如何檢查多個選項中的項目
- 12. Xtext可選項目的無序列表
- 13. 我如何訪問我選擇的項目? ListBox
- 14. 如何訪問Xtext驗證程序中的上下文信息?
- 15. Android:如何更改首選項中的選定項目顏色?
- 16. 如何獲得用戶從首選項中選擇的項目的值?
- 17. 訪問多個共享首選項
- 18. 訪問iphone設置首選項
- 19. 訪問EditText首選項對話框
- 20. 從庫項目C訪問項目類#
- 21. 我想訪問我從Red Hat機器運行的Django項目
- 22. 如何訪問我的Google App Engine項目的API瀏覽器?
- 23. 如何從Java項目調用Xtext解析器/ JvmModelInferrer
- 24. 如何從appdelegate訪問uitablviews選定的項目?
- 25. 訪問所選項目從中繼
- 26. 訪問服務器上的設置/首選項文件
- 27. 無法使用統一首選項保留我的首選項
- 28. 如何驗證選項組中的選項按鈕,如果沒有選擇作出訪問vba
- 29. 如何在瀏覽器中訪問我的zend項目?
- 30. Mvvmcross,如何從我的Android項目訪問ViewModel