blob: 66e5e76dec7ee5996e85b1eec6087475661a9407 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007 IBM Corporation and Others
* 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.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentarou FUKUDA - initial API and implementation
*******************************************************************************/
package org.eclipse.actf.model.ui.editor.actions;
import java.util.Map;
import org.eclipse.actf.model.ui.IModelService;
import org.eclipse.actf.model.ui.editor.browser.IWebBrowserACTF;
import org.eclipse.actf.model.ui.editor.dialogs.FavoritesAddDialog;
import org.eclipse.actf.model.ui.internal.FavoritesChangeEvent;
import org.eclipse.actf.model.ui.internal.FavoritesUtil;
import org.eclipse.actf.model.ui.util.ModelServiceMessages;
import org.eclipse.actf.model.ui.util.ModelServiceUtils;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.IWorkbenchWindow;
public class AddFavoritesAction extends FavoritesAction {
public static final String ID = AddFavoritesAction.class.getName();
private IWorkbenchWindow _window;
public AddFavoritesAction(IWorkbenchWindow window, Map favoritesMap) {
this._window = window;
setId(ID);
setText(ModelServiceMessages.getString("MenuConst.AddFavorites")); //$NON-NLS-1$
}
public void run() {
if (null != this._window) {
IModelService modelService = ModelServiceUtils.getActiveModelService();
if(modelService==null){
return;
}
String title = modelService.getURL();
if(modelService instanceof IWebBrowserACTF){
title = ((IWebBrowserACTF)modelService).getLocationName();
}
Map<String, String> tmpMap = FavoritesUtil.getFavoritesMap();
FavoritesAddDialog addDialog = new FavoritesAddDialog(this._window.getShell(), tmpMap, title);
int ret = addDialog.open();
if (ret==IDialogConstants.OK_ID) {
String url = modelService.getURL();
tmpMap.put(addDialog.getName(), url);
FavoritesUtil.saveFavoritesMap(tmpMap);
FavoritesChangeEvent fce = new FavoritesChangeEvent(this, tmpMap);
fireFavoritesChanged(fce);
}
}
}
}