/* ********************************************************************** **
** Copyright notice **
** **
** (c) 2005-2006 RSSOwl Development Team **
** http://www.rssowl.org/ **
** **
** All rights reserved **
** **
** This program and the accompanying materials are made available under **
** the terms of the Eclipse Public License v1.0 which accompanies this **
** distribution, and is available at: **
** http://www.rssowl.org/legal/epl-v10.html **
** **
** A copy is found in the file epl-v10.html and important notices to the **
** license from the team is found in the textfile LICENSE.txt distributed **
** in this package. **
** **
** This copyright notice MUST APPEAR in all copies of the file! **
** **
** Contributors: **
** RSSOwl Development Team - initial API and implementation **
** **
** ********************************************************************** */
package org.rssowl.ui.internal.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.rssowl.core.persist.IEntity;
import org.rssowl.core.persist.IFolder;
import org.rssowl.core.persist.IFolderChild;
import org.rssowl.core.persist.dao.DynamicDAO;
import org.rssowl.core.persist.dao.IPreferenceDAO;
import org.rssowl.core.persist.reference.FolderReference;
import org.rssowl.ui.internal.OwlUI;
import org.rssowl.ui.internal.dialogs.SearchNewsDialog;
import org.rssowl.ui.internal.util.ModelUtils;
import org.rssowl.ui.internal.views.explorer.BookMarkExplorer;
import java.util.ArrayList;
import java.util.List;
/**
* @author bpasero
*/
public class SearchInTypeAction extends Action {
private ISelectionProvider fSelectionProvider;
private IWorkbenchWindow fWindow;
/**
* @param window
* @param selectionProvider
*/
public SearchInTypeAction(IWorkbenchWindow window, ISelectionProvider selectionProvider) {
fWindow = window;
fSelectionProvider = selectionProvider;
setText("Search News...");
setImageDescriptor(OwlUI.getImageDescriptor("icons/obj16/searchmark.gif"));
}
/*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) fSelectionProvider.getSelection();
if (selection.isEmpty()) {
String selectedBookMarkSetPref = BookMarkExplorer.getSelectedBookMarkSetPref(OwlUI.getWindow());
Long selectedRootFolderID = DynamicDAO.getDAO(IPreferenceDAO.class).load(selectedBookMarkSetPref).getLong();
selection = new StructuredSelection(new FolderReference(selectedRootFolderID).resolve());
}
List<IFolderChild> entities = ModelUtils.getFoldersAndBookMarks(selection);
List<IEntity> entitiesTmp = new ArrayList<IEntity>(entities);
/* Normalize */
for (IEntity entity : entitiesTmp) {
if (entity instanceof IFolder)
ModelUtils.normalize((IFolder) entity, entities);
}
SearchNewsDialog dialog = new SearchNewsDialog(fWindow.getShell(), entities);
dialog.open();
}
}