package com.onaro.sanscreen.client.view.actions.authorizedpath; import java.awt.event.ActionEvent; import java.util.Date; import java.util.ResourceBundle; import com.onaro.sanscreen.client.MainDirector; import com.onaro.sanscreen.client.SANscreenClientPlugin; import com.onaro.sanscreen.client.navigation.GoToAction; import com.onaro.sanscreen.client.view.ActionFactory; import com.onaro.sanscreen.client.view.ViewDirector; import com.onaro.sanscreen.client.view.actions.Messages; import com.onaro.sanscreen.client.view.selection.ObjectSelectionModel; import com.onaro.sanscreen.client.view.selection.SelectedObject; import com.onaro.sanscreen.client.view.tabular.NavigationInfo; import com.onaro.sanscreen.server.interfaces.ServerInterfacesUtils; import com.onaro.util.IllegalInitException; import com.onaro.util.enumeration.EnumPresentation; import com.onaro.util.jfc.ConfigurableAction; /** * An {@link javax.swing.Action} that when performed, pops up a wizard for authorizing * the paths selected by the user. */ public class GotoPlanningAction extends ConfigurableAction { public static final String ID = "GotoPlanning"; //$NON-NLS-1$ private static final long serialVersionUID = 1L; private ViewDirector targetView; /** * Initialize the action, setting its name, icon, tooltip and mnemonic. * @param name the name of this action * @param resources locale dependent resources, used for initializing this action's * properties * @throws com.onaro.util.InvalidConfigException if failed to get any resources */ public GotoPlanningAction(String name, ResourceBundle resources) throws IllegalInitException { super(name, resources); } /** * Initialize the action, setting its name, icon, tooltip and mnemonic. * @param conf allow the action to get its name which is used for fetching resources * @param resources locale dependent resources, used for initializing this action's * properties * @throws com.onaro.util.InvalidConfigException if failed to get any resources */ public GotoPlanningAction(ActionFactory.ActionInitInfo actionInitInfo, ResourceBundle resources, ViewDirector targetView) throws IllegalInitException { super(actionInitInfo,resources); this.targetView = targetView; } /** * goto the planning view and shows only the tasks that are related to the violation */ public void actionPerformed(ActionEvent e) { assert targetView.getObjectSelectionModel().size() == 1 : "assuming single selection"; //$NON-NLS-1$ SelectedObject selectedContext = targetView.getObjectSelectionModel().first(); //the violation id is passed to the planning view and used in the query to flag those tasks that are related to the violation long violationId = selectedContext.getViolationId(); //the violation description for the planning sub-title String violationDescription = getViolationDescription(selectedContext); Date violationContext = ServerInterfacesUtils.getLocalDate(ServerInterfacesUtils.getLoadContext(selectedContext.getContext())); //show the planning view, with the related tasks flagged and filtered NavigationInfo navigationInfo = new NavigationInfo("violation", violationDescription, String.valueOf(violationId)); //$NON-NLS-1$ navigationInfo.setParameter("violationTime", String.valueOf(violationContext.getTime())); //$NON-NLS-1$ MainDirector.getFrameDirector().loadView("views.tasks", "views.tasks.list", null, GoToAction.APPLICATION, navigationInfo); //$NON-NLS-1$ //$NON-NLS-2$ } /** * construct the description in the sub-title of the planning view * this text explains that the tasks related to the violation are shown */ private String getViolationDescription(SelectedObject selectedContext) { String violationTypeName = selectedContext.getStringProperty("ViolationType"); //$NON-NLS-1$ EnumPresentation.Attributes violationType = SANscreenClientPlugin.getDefault().getEnumPresentation().getAttributes("ViolationTypeEnum", violationTypeName); //$NON-NLS-1$ String hostName = selectedContext.getStringProperty("SourceName"); //$NON-NLS-1$ String storageName = selectedContext.getStringProperty("TargetName"); //$NON-NLS-1$ String volumeName = selectedContext.getVolumeName(); StringBuilder buffer = new StringBuilder(""); //$NON-NLS-1$ if(volumeName != null && volumeName.length() > 0) { buffer.append(Messages.INSTANCE.getPlanningViolationBetweenHostStorageWithVolumeText( violationType.name, hostName, storageName, volumeName)); } else { buffer.append(Messages.INSTANCE.getPlanningViolationBetweenHostStorageText( violationType.name, hostName, storageName)); } buffer.append(""); //$NON-NLS-1$ return buffer.toString(); } /** * enable the goto action if only one violation is selected and there is at least one task that is related to that violation * @param selection the selection of the violations */ public void setEnableBySelection(ObjectSelectionModel selection) { //only single selection is supported boolean oneSelected = selection.size() == 1; if (oneSelected) { SelectedObject selectedObj = selection.first(); //check if the violation has related tasks boolean planned = selectedObj.getBoolean("Planned"); //$NON-NLS-1$ setEnabled(planned); }else{ setEnabled(false); } } }