I have created a preference page in eclipse the preference page has two fields
server url
store location
If the user open this preferences dialog, change the value of url and apply it the product is restarted and after restart when I check the value in the url field it is changed as expected. When I change the values of both url and directory only one of them is updated depends on which one is changed later.
Here is my init method which initialize the preferences
public class DataStorePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public static final String SERVER_URL = "prefs_server_url";
public static final String WORKSPACE_DIR = "prefs_workspace_dir";
public static final String KEEP_LOCKS = "prefs_keep_locks";
//public static final String RELEASE = "prefs_release";
public DataStorePreferencePage() {
super(GRID);
}
#Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
#Override
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
System.setProperty("datastoreserver_url", property);
if (property.equals(DataStorePreferencePage.WORKSPACE_DIR) ||
property.equals(DataStorePreferencePage.SERVER_URL)) {
if(MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Information", "New settings will be applied after a restart.\nRestart now?"))
PlatformUI.getWorkbench().restart();
}
}
});
}
#Override
protected void createFieldEditors() {
StringFieldEditor urlEditor = new StringFieldEditor(SERVER_URL, "DataStore Server URL", getFieldEditorParent());
StringFieldEditor workspaceDirEditor = new DirectoryFieldEditor(WORKSPACE_DIR, "Workspace directory:", getFieldEditorParent());
BooleanFieldEditor keepLocksEditor = new BooleanFieldEditor(KEEP_LOCKS, "Keep locks (default setting):", getFieldEditorParent());
//BooleanFieldEditor releaseEditor = new BooleanFieldEditor(RELEASE, "Release (default setting):", getFieldEditorParent());
addField(workspaceDirEditor);
addField(urlEditor);
addField(keepLocksEditor);
//addField(releaseEditor);
}
#Override
public boolean performOk() {
return super.performOk();
}
}
Question:
Where is the new value stored? From where eclipse get this changed value in any .ini file?
How can I change both the properties at the same time?
Thanks
Wait until performOk or performApply is called before checking for restart.
The preference values are stored in the preference store. You can get them with:
IPreferenceStore store = getPreferenceStore();
String dir = store.getString(WORKSPACE_DIR);
String url = store.getString(SERVER_URL);
Related
We do have got preference page:
public class PreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage
{
// another preferences...
// add checkbox - enable export path setting
Composite exportPathControl = getFieldEditorParent();
exportPathC = new BooleanFieldEditor(PreferenceConstants.P_SETEXPORTPATHPREFERENCEPAGE, SetExportPathStrPref, exportPathControl);
addField(exportPathC);
boolean enableSetExportPathControl = Activator.getDefault().
getPreferenceStore().getBoolean(PreferenceConstants.P_SETEXPORTPATHPREFERENCEPAGE);
boolean checked = exportPathC.getBooleanValue();
// Path
setExportPathControl = getFieldEditorParent();
browserFE = new CustomDirectoryFieldEditor(PreferenceConstants.P_EXPORTPATHPREFERENCEPAGE,
ExportPathStrPref, setExportPathControl ,enableSetExportPathControl);
browserFE.setEmptyStringAllowed(false);
addField(browserFE);
// enable/disable export path DirectoryFieldEditor according to exportPathC
browserFE.setEnabled(enableSetExportPathControl, setExportPathControl);
((Button) exportPathC.getDescriptionControl(exportPathControl)).addSelectionListener(exportPathControlListener());
}
We do need avoid of checking browserFE if is disabled (exportPathC is deselected). We handled error message with browserFE.enableValidation(setExportPathEnabled):
// enable/disable possibility to set path according BooleanFieldEditor exportPathC
private SelectionListener exportPathControlListener()
{
return new SelectionListener()
{
#Override
public void widgetSelected(SelectionEvent event)
{
if (event.widget instanceof Button)
{
Boolean setExportPathEnabled = ((Button) event.widget).getSelection();
browserFE.setEnabled(setExportPathEnabled, setExportPathControl);
browserFE.enableValidation(setExportPathEnabled);
browserFE.checkState();
}
}
#Override
public void widgetDefaultSelected(SelectionEvent e)
{
widgetSelected(e);
}
};
}
But how to enable Apply button?
There is org.eclipse.jface.preference.FieldEditorPreferencePage.checkState(), but protected.
We could override org.eclipse.jface.preference.PreferencePage.isValid() and set it's output to true, but what is more paths are wrong? We do knot know, which path causes trouble, org.eclipse.jface.preference.FieldEditorPreferencePage.invalidFieldEditor is private as well.
Any idea? Thanks for any hint!!
I have implemented a function to download aws s3 files using the following code:
public void credentialsProvider()
{
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(), "us-east-2:xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxx", Regions.US_EAST_2
);
setAmazonS3Client(credentialsProvider);
System.out.println("setAmazonS3Client done");
}
public void setAmazonS3Client( CognitoCachingCredentialsProvider credentialsProvider)
{
s3 = new AmazonS3Client(credentialsProvider);
s3.setRegion(Region.getRegion(Regions.US_EAST_2));
}
public void setTransferUtility()
{
transferUtility = new TransferUtility(s3, getApplicationContext());
System.out.println("setTransferUtility done");
}
public void setFileDownload()
{
final String path = this.getFilesDir().getAbsolutePath();
File myFile = new File(path);
TransferObserver transferObserver = transferUtility.download("sample-bucket-001", "images-4.jpeg", myFile);
transferObserverListener(transferObserver);
}
public void transferObserverListener(TransferObserver transferObserver)
{
transferObserver.setTransferListener(new TransferListener() {
#Override
public void onStateChanged(int id, TransferState state) {
System.out.println("onStateChanged: "+ state);
if(state == TransferState.FAILED || state == TransferState.WAITING_FOR_NETWORK){
}
}
#Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
int percentage = (int)(bytesCurrent/bytesTotal * 100);
System.out.println("percentage: "+ percentage);
}
#Override
public void onError(int id, Exception ex) {
System.out.println("Error faced: "+ ex.toString());
}
});
}
As I try to execute the following code I get the following error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxxx.xxxxxxxx/com.xxxxxx.xxxxxxxx.Activity}: java.lang.IllegalArgumentException: Invalid file: /data/user/0/com.xxxxxx.xxxxxxxx/files/
I cannot save the file on external storage as I prefer to have them hidden and protected, and deleted in case the app got deleted. I used to use the path to save files on it, that are directly loaded from the internet and no problem there.
Kindly advise on the matter.
The file path supplied to TransferUtility needs to include a file name, e.g.:
final String path = this.getFilesDir().getAbsolutePath() + "images-4.jpeg";
I have finally found the solution to the question asked, which simple using a path that is totally new, unused previously, so it can create the folder that where it will store the downloaded picture or file.
final String path = this.getFilesDir().getAbsolutePath()+"/zip";
I wish Amazon's feedback could be a bit more specific than just 'invalid file'.
Inside the onConsentFormLoaded method it says for “variable ‘form’ is accessed from within inner class must be declared final” but then when I declare it final it then shows a error “variable ‘form’ might not have been initialized” I tried declaring 'private static ConsentForm form" at the top of my class but then it gives a error saying about placing android context classes inside a static field will result in a memory leak so im not sure where to go from here ?
public static void settings()
{
final AppActivity activity = ((AppActivity) Cocos2dxHelper.getActivity());
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
URL privacyUrl = null;
try {
// TODO: Replace with your app’s privacy policy URL.
privacyUrl = new URL(“https://privacy-policy”);
} catch (MalformedURLException e) {
e.printStackTrace();
}
ConsentForm form = new ConsentForm.Builder(getContext(), privacyUrl).withListener(new ConsentFormListener() {
#Override
public void onConsentFormLoaded() {
// Consent form loaded successfully.
Log.i(“consent”, “consent loaded”);
form.show();
}
#Override
public void onConsentFormOpened() {
// Consent form was displayed.
}
#Override
public void onConsentFormClosed(ConsentStatus consentStatus, Boolean userPrefersAdFree) {
}
#Override
public void onConsentFormError(String errorDescription) {
// Consent form error.
Log.i(“consent”, errorDescription);
}
})
.withPersonalizedAdsOption().withNonPersonalizedAdsOption().build();
form.load();
}
});
}
I'm trying to mount an ImageResourceReference on my Page, but the ExternalLink is mounted multiple times (everytime I reload the page, I get a new additional link (same one).
For example when I start the server and load the page for the first time, there's just one ExternalLink, the second time, two links, third time three, etc...
What could be the reason for that?
Here is my code:
WebApp.java:
void init() {
.....
mountResource("/book/number/${number}/images/ray/${name}", new ImageResourceReference());
....
}
ImageResourcesPanel:
public class ImageResourcesPanel extends Panel {
private static final long serialVersionUID = -8723530004274531683L;
private static Logger logger = LoggerFactory.getLogger(ImageResourcesPanel.class
.getName());
/**
* The image names for which dynamic images will be generated
*/
private static List<String> IMAGE_NAMES = new ArrayList<String>();
public ImageResourcesPanel(final String wicketId, final IModel<Device> model) {
super(wicketId, model);
String pathToImage = "images";
IMAGE_NAMES.add(pathToImage);
ListView<String> listView = new ListView<String>("list", IMAGE_NAMES) {
private static final long serialVersionUID = 1L;
#Override
protected void populateItem(ListItem<String> item) {
logger.debug("Executed!");
ResourceReference imagesResourceReference = new ImageResourceReference();
PageParameters imageParameters = new PageParameters();
int number = model.getObject().getNumber();
String imageName = item.getModelObject();
String folder = model.getObject().getLinkToFolder();
imageParameters.set("name", imageName);
imageParameters.set("number", number);
imageParameters.set("folder", folder);
// generates nice looking url (the mounted one) to the current image
CharSequence urlForWordAsImage = getRequestCycle().urlFor(imagesResourceReference, imageParameters);
ExternalLink link = new ExternalLink("link", urlForWordAsImage.toString());
link.setBody(Model.of(imageName));
item.add(link);
}
};
add(listView);
}
}
Got it!
I just had to make the ListView empty after mounting the image on the page. I just added a line of code after adding the link to the ListView-Item:
`IMAGE_NAMES.remove(pathToImage);`
My problem is annoying. My server side is generating 12 random numbers (double here).
My Client side received the correct data but nothing is displayed in my Chart. That worked fine with hardcoded data in the store but not with a REST call.
The transfer between my server and my client is that :
[{"key":"key0","value":0.47222548599297787},{"key":"key1","value":0.6009173797369691},{"key":"key2","value":0.13880104282435624},{"key":"key3","value":0.01804674319345545},{"key":"key4","value":0.5547733564202956},{"key":"key5","value":0.8229999661308851},{"key":"key6","value":0.8959346004391032},{"key":"key7","value":0.6848052288628435},{"key":"key8","value":0.10222856671111813},{"key":"key9","value":0.6931371931409103},{"key":"key10","value":0.2994297934549003},{"key":"key11","value":0.47566752196381334}]
Here my simple class used for my test. I am a newbie with GXT 3
public void onModuleLoad() {
final ListStore<JSOModel> store;
final ContentPanel panel = new FramedPanel();
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "/ws/DocumentService/v1/test");
builder.setHeader("Accept", "application/json");
HttpProxy proxy = new HttpProxy(builder);
final Loader<ListLoadConfig, ListLoadResult<JSOModel>> loader = new ListLoader<ListLoadConfig, ListLoadResult<JSOModel>>(proxy, new DataReader<ListLoadResult<JSOModel>, String>() {
#Override
public ListLoadResult<JSOModel> read(Object loadConfig, String data) {
List<JSOModel> jsoModels = new ArrayList<JSOModel>();
JsArray<JSOModel> jsoModelJsArray = JSOModel.arrayFromJson(data);
if(jsoModelJsArray != null) {
for(int i = 0; i < jsoModelJsArray.length(); i++) {
jsoModels.add(jsoModelJsArray.get(i));
}
}
return new ListLoadResultBean<JSOModel>(jsoModels);
}
});
store = new ListStore<JSOModel>(new ModelKeyProvider<JSOModel>() {
#Override
public String getKey(JSOModel item) {
return item.get("key");
}
});
loader.addLoadHandler(new LoadResultListStoreBinding<ListLoadConfig, JSOModel, ListLoadResult<JSOModel>>(store) {
#Override
public void onLoad(LoadEvent<ListLoadConfig, ListLoadResult<JSOModel>> event) {
ListLoadResult<JSOModel> loaded = event.getLoadResult();
if(loaded.getData() == null) {
store.replaceAll(new ArrayList<JSOModel>());
} else {
store.replaceAll(loaded.getData());
}
}
});
Chart<JSOModel> chart = new Chart<JSOModel>();
chart.setStore(store);
chart.setShadowChart(true);
NumericAxis<JSOModel> axis = new NumericAxis<JSOModel>();
axis.setPosition(Chart.Position.LEFT);
axis.addField(new ValueProvider<JSOModel, Number>() {
#Override
public Number getValue(JSOModel JSOModel) {
return JSOModel.getNumber("value");
}
#Override
public void setValue(JSOModel JSOModel, Number number) {
}
#Override
public String getPath() {
return "key";
}
});
axis.setTitleConfig(new TextSprite("Number of hits"));
axis.setWidth(50);
axis.setMinimum(0);
axis.setMaximum(100);
chart.addAxis(axis);
PathSprite odd = new PathSprite();
odd.setOpacity(1);
odd.setFill(new Color("#dff"));
odd.setStroke(new Color("#aaa"));
odd.setStrokeWidth(0.5);
axis.setGridOddConfig(odd);
CategoryAxis<JSOModel, String> horizontalAxis = new CategoryAxis<JSOModel, String>();
horizontalAxis.setPosition(Chart.Position.BOTTOM);
horizontalAxis.setField(new ValueProvider<JSOModel, String>() {
#Override
public String getValue(JSOModel JSOModel) {
return JSOModel.get("key");
}
#Override
public void setValue(JSOModel JSOModel, String s) {
}
#Override
public String getPath() {
return "key";
}
});
horizontalAxis.setTitleConfig(new TextSprite("month of year"));
chart.addAxis(horizontalAxis);
LineSeries<JSOModel> column = new LineSeries<JSOModel>();
column.setYAxisPosition(Chart.Position.LEFT);
column.setStroke(new RGB(148,174,10));
column.setHighlighting(true);
chart.addSeries(column);
axis.addField(column.getYField());
chart.addSeries(column);
chart.setHeight(100);
chart.setWidth(100);
Button b = new Button("ha");
b.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent clickEvent) {
loader.load();
}
});
RootPanel.get().add(b);
panel.setCollapsible(true);
panel.setHeadingText("Column Chart");
panel.setPixelSize(620, 500);
panel.setBodyBorder(true);
VerticalLayoutContainer layout = new VerticalLayoutContainer();
panel.add(layout);
chart.setLayoutData(new VerticalLayoutContainer.VerticalLayoutData(1,1));
layout.add(chart);
chart.setBackground(new Color("#dff"));
RootPanel.get().add(panel);
There are two ways to wire the chart into a store. One is to simply specify that the chart is using a store via setStore, as you have done:
chart.setStore(store);
When you do this, you must also inform the chart when it must redraw everything - you must call:
chart.redrawChart();
This call must be made shortly after the load is completed - consider doing it at the end of onLoad.
Why is this required? In some cases, developers want to make many changes to the store, one at a time, and if the chart automatically updated after each change, that would spawn many slow changes to the data model, and could end up looking strange. In a case like this, you would only call redrawChart() after all changes were complete.
There is another option however - instead of calling setStore, you can call bindStore, and ask the Chart to automatically update whenever any change occurs to the chart:
chart.bindStore(store);
In your case, this is likely the correct answer.