package com.onaro.sanscreen.client.view.actions; import java.util.List; import java.util.ResourceBundle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.core.runtime.IAdaptable; import com.onaro.sanscreen.client.prefs.ClientPrefs; import com.onaro.sanscreen.client.view.ActionFactory; import com.onaro.sanscreen.client.view.CompositeDirectorDialog; import com.onaro.sanscreen.client.view.ViewDirector; import com.onaro.sanscreen.client.view.ViewDirectorFactory; import com.onaro.sanscreen.client.view.init.CompositeDirectorInitInfo; import com.onaro.sanscreen.client.view.init.ViewDirectorInitInfo; import com.onaro.util.IllegalInitException; import com.onaro.util.InvalidConfigException; /** * Action used to display the "Analyze Storage Pools" dialog. */ public class ShowStoragePoolDashboardAction extends MultipleSelectionAction { private static final long serialVersionUID = 1L; private static final Logger logger = LogManager.getLogger(ShowStoragePoolDashboardAction.class); public static final String ID = "ShowStoragePoolDashboardAction"; //$NON-NLS-1$ public static final String NAME = "dialogs.storagepool.dashboard"; //$NON-NLS-1$ public ShowStoragePoolDashboardAction(String name, ResourceBundle resources, ViewDirector targetView) throws IllegalInitException { super(name, resources, targetView); } public ShowStoragePoolDashboardAction(ActionFactory.ActionInitInfo actionInitInfo, ResourceBundle resources, ViewDirector targetView) throws IllegalInitException { super(actionInitInfo, resources, targetView); } @Override protected void doAction(List objs, int index, boolean doForAll) { try { CompositeDirectorDialog dialog = new StoragePoolDashboardDialog(getResources()); dialog.setSelectedObjects(getSelectedAdaptables()); dialog.showDialog(); } catch (IllegalInitException e) { logger.error(e); } } @Override protected boolean actionNeeded(IAdaptable selectedObj) { return true; } @Override protected void promptForConfirmation(List objs, int index, boolean isLastObj) throws DoForAllException, CancelOperationException { //no need for confirmation. the action opens it's own dialog throw new DoForAllException(); } @Override protected String getMessageResource() { throw new UnsupportedOperationException("Not supported. Should not be called"); //$NON-NLS-1$ } private static class StoragePoolDashboardDialog extends CompositeDirectorDialog { private static final long serialVersionUID = 1L; private static final String RESOURCE_KEY = "dialog.assurance.storagepool.analyze"; //$NON-NLS-1$ private static final String DIALOG_NAME = "views.dialog.storagePool.analyzer"; //$NON-NLS-1$ private static final String STORAGE_POOLS_VIEW_ID = "views.inventory.storage.pools"; //$NON-NLS-1$ private static final String STORAGE_POOLS_VIEW_TYPE = "StoragePoolsViewDirector"; //$NON-NLS-1$ private static final String STORAGE_POOLS_DASHBOARD_ID = "view.analyze.micro.storagePool"; //$NON-NLS-1$ private static final String STORAGE_POOLS_DASHBOARD_TYPE = "StoragePoolDashboardDirector"; //$NON-NLS-1$ public StoragePoolDashboardDialog(ResourceBundle resources) throws IllegalInitException { super(DIALOG_NAME, STORAGE_POOLS_VIEW_ID, createInitInfo(), resources, resources, ClientPrefs.getView(), RESOURCE_KEY); } private static CompositeDirectorInitInfo createInitInfo() { CompositeDirectorInitInfo initInfo = new CompositeDirectorInitInfo(DIALOG_NAME); try { ViewDirectorInitInfo storagePoolsInitInfo = ViewDirectorFactory.getViewDirectorInitInfo(null, STORAGE_POOLS_VIEW_ID, STORAGE_POOLS_VIEW_TYPE); initInfo.addMainView(storagePoolsInitInfo); ViewDirectorInitInfo dashboardInitInfo = ViewDirectorFactory.getViewDirectorInitInfo(null, STORAGE_POOLS_DASHBOARD_ID, STORAGE_POOLS_DASHBOARD_TYPE); initInfo.addMicroView(dashboardInitInfo); } catch (InvalidConfigException e) { logger.error("Error creating view - " + e.getMessage(), e); //$NON-NLS-1$ } return initInfo; } } }