Search in sources :

Example 1 with SnippetManager

use of org.eclipse.wst.common.snippets.internal.model.SnippetManager in project liferay-ide by liferay.

the class SnippetsUtil method importSnippetsFromFile.

@SuppressWarnings("rawtypes")
public static void importSnippetsFromFile(File snippetFile) throws FileNotFoundException {
    if ((snippetFile == null) || !snippetFile.exists() || !snippetFile.isFile()) {
        return;
    }
    // InputStream stream = Files.newInputStream(snippetFile.toPath());
    SnippetDefinitions definitions = ModelFactoryForUser.getInstance().load(snippetFile.getAbsolutePath());
    List importCategories = definitions.getCategories();
    SnippetManager manager = SnippetManager.getInstance();
    List currentCategories = manager.getDefinitions().getCategories();
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            for (int i = 0; i < importCategories.size(); i++) {
                boolean found = false;
                for (int j = 0; j < currentCategories.size(); j++) {
                    if (((PaletteEntry) currentCategories.get(j)).getId().compareToIgnoreCase(((PaletteEntry) importCategories.get(i)).getId()) == 0) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    SnippetManager manager = SnippetManager.getInstance();
                    manager.getPaletteRoot().add((PaletteEntry) importCategories.get(i));
                }
            }
        }
    });
// IViewPart view = findSnippetsView();
// if (view != null) {
// SnippetsView snippetsView = (SnippetsView) view;
// snippetsView.getViewer().getContents().refresh();
// }
}
Also used : List(java.util.List) SnippetManager(org.eclipse.wst.common.snippets.internal.model.SnippetManager) PaletteEntry(org.eclipse.gef.palette.PaletteEntry) SnippetDefinitions(org.eclipse.wst.common.snippets.internal.SnippetDefinitions)

Aggregations

List (java.util.List)1 PaletteEntry (org.eclipse.gef.palette.PaletteEntry)1 SnippetDefinitions (org.eclipse.wst.common.snippets.internal.SnippetDefinitions)1 SnippetManager (org.eclipse.wst.common.snippets.internal.model.SnippetManager)1