package com.onaro.sanscreen.client.view.actions.migration; import java.awt.event.ActionEvent; import java.util.Collections; import java.util.List; import java.util.ResourceBundle; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import com.onaro.sanscreen.client.SessionsHelper; import com.onaro.sanscreen.client.error.CentralErrorHandler; import com.onaro.sanscreen.client.view.ActionFactory; import com.onaro.sanscreen.client.view.ViewDirector; import com.onaro.sanscreen.client.view.actions.SingleSelectionAction; import com.onaro.sanscreen.client.view.selection.ObjectSelectionModel; import com.onaro.sanscreen.client.view.selection.SelectedObject; import com.onaro.sanscreen.server.migration.sessions.MigrationException; import com.onaro.util.IllegalInitException; import com.onaro.util.jfc.Dialogs; import com.onaro.util.jfc.RoleRestrictedAction; /** * Capture the paths of migrated switches for soem tasks. * Multiple selection */ public class CaptureMigratedPathsAction extends SingleSelectionAction implements RoleRestrictedAction { private static final long serialVersionUID = 1L; public CaptureMigratedPathsAction(ActionFactory.ActionInitInfo actionInitInfo, ResourceBundle resources, ViewDirector targetView) throws IllegalInitException { super(actionInitInfo, resources, targetView); } protected boolean isSelected(ObjectSelectionModel selectionModel) { return selectionModel.size() == 1; } public void actionPerformed(ActionEvent evt) { try { SelectedObject selectedObject = getSelection(); List id = Collections.singletonList(selectedObject.getObjIdLong()); String name = selectedObject.getName(); boolean confirmed = new Dialogs(resources).getConfirmation(SwingUtilities.getRootPane(targetView.getComponent(true)), JOptionPane.QUESTION_MESSAGE, "action.switch.migration.capture.migrated.paths.confirm", new Object[]{name}); //$NON-NLS-1$ if(confirmed){ SessionsHelper.getInstance().getMigrationSession().updateSnapshotPaths(id); } } catch (MigrationException e) { CentralErrorHandler.handle("Failed to capture migrated path", e); //$NON-NLS-1$ } catch (SessionsHelper.SessionsException e) { CentralErrorHandler.handle("Failed to capture migrated path", e); //$NON-NLS-1$ } } }