Skip to content

Commit

Permalink
import fully ready
Browse files Browse the repository at this point in the history
  • Loading branch information
semanticsoft committed Jan 29, 2014
1 parent 11ab166 commit a9276d6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.eclipse.core.runtime.preferences.IPreferenceFilter;
import org.lunifera.vaaclipse.ui.preferences.model.FieldEditor;
import org.lunifera.vaaclipse.ui.preferences.model.PreferencesPage;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -171,14 +176,35 @@ protected List<PreferencesPage> getSelectedPages() {
return list;
}

protected IPreferenceFilter createFilter(List<PreferencesPage> selectedPages) {
final Set<String> set = new HashSet<>();
for (PreferencesPage p : selectedPages) {
for (FieldEditor<?> e : p.getChildren()) {
set.add(e.getEquinoxPath());
}
}

return new IPreferenceFilter() {

@Override
public String[] getScopes() {
return (String[]) set.toArray(new String[set.size()]);
}

@Override
public Map<?, ?> getMapping(String scope) {return null;}
};
}

protected StringBuffer toTextWithCatName(List<PreferencesPage> selectedPages) {
StringBuffer exportedPrefNames = new StringBuffer();
StringBuffer prefNames = new StringBuffer();
for (PreferencesPage page: selectedPages) {
String name = page.getCategory().getName();
if (name == null)
name = "NoName";
exportedPrefNames.append(name + ", ");
prefNames.append(name + ", ");
}
return exportedPrefNames;
prefNames.delete(prefNames.length()-2, prefNames.length()-1);
return prefNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,6 @@ public InputStream getStream() {
}, "preferences.epf");
}

protected IPreferenceFilter createFilter(List<PreferencesPage> selectedPages) {
final Set<String> set = new HashSet<>();
for (PreferencesPage p : selectedPages) {
for (FieldEditor<?> e : p.getChildren()) {
set.add(e.getEquinoxPath());
}
}

return new IPreferenceFilter() {

@Override
public String[] getScopes() {
return (String[]) set.toArray(new String[set.size()]);
}

@Override
public Map<?, ?> getMapping(String scope) {return null;}
};
}

@SuppressWarnings("restriction")
@Override
protected void doAction() {
Expand All @@ -116,8 +96,6 @@ protected void doAction() {

StringBuffer exportedPrefNames = toTextWithCatName(selectedPages);

exportedPrefNames.delete(exportedPrefNames.length()-2, exportedPrefNames.length()-1);

setStatusText("Preferences was exported: " + exportedPrefNames.toString());

if (downloadButton == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.core.internal.preferences.PreferencesService;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.IExportedPreferences;
import org.eclipse.core.runtime.preferences.IPreferenceFilter;
import org.lunifera.vaaclipse.ui.preferences.addon.internal.util.PrefHelper;
import org.lunifera.vaaclipse.ui.preferences.model.FieldEditor;
import org.lunifera.vaaclipse.ui.preferences.model.PreferencesCategory;
Expand Down Expand Up @@ -75,8 +76,10 @@ public Component getComponent(OptionDialog optionDialog) {
@Override
protected void doAction() {

if (toImport == null)
if (toImport == null) {
setStatusText("No uploaded preferences for import. Upload preferences file.");
return;
}

List<PreferencesPage> selectedPages = getSelectedPages();
if (selectedPages.isEmpty()) {
Expand All @@ -85,15 +88,8 @@ protected void doAction() {
}

try {
for (PreferencesPage page : selectedPages) {
if (page.getCategory() != null) {
for (FieldEditor<?> editor : page.getChildren()) {
//TODO: import
}
}
}
}
catch (Exception e) {
PreferencesService.getDefault().applyPreferences(toImport, new IPreferenceFilter[] {createFilter(selectedPages)});
} catch (CoreException e) {
logger.error("Error when import preferences", e);
setStatusText("Import preferences failed");
return;
Expand Down

0 comments on commit a9276d6

Please sign in to comment.