package com.onaro.sanscreen.client.view; import com.onaro.sanscreen.client.view.CompositeDirector.ViewAdapter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class ViewSorter { /* Desired order of all microviews. Each time we build a set of microviews we will sort them based on this list for consistency. */ private static final List MICRO_VIEW_ORDER = new ArrayList(); static { MICRO_VIEW_ORDER.add("views.inventory.summary"); // Summary (landing page) //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.properties"); // Properties //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.sa.properties"); // Target Element Properties //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.reported.by"); // Data sources //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.changes"); // Changes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.perf.changes"); // Performance Changes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.tasks.changes"); // Task Changes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.ports"); // Ports //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.perf.micro.traffic.analyzer"); // Switch Port Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.performance.dialog.traffic.analyzer");// Switch Port Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.iscsiSessions"); // iSCSI sessions //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.networkPortals"); // Network Portals //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.zone"); // Zone Members //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.masking"); // Masking //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.storage.nodes"); // Storage Nodes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.disk"); // Disks //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.storage.pools"); // Storage Pools //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.internal.volume"); // Internal Volumes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.virtual.storage"); // Virtual Storage //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.backend.volume"); // Backend Volumes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.volume.storage"); // Volumes //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.qtree"); // Qtrees //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.nas.micro.quotas"); // Quotas //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.nas.micro.shares"); // Shares //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.file.systems"); // File Systems //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.path"); // Paths //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.apls"); // Policies //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.sa.policies"); // Policies //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.sa.violation.list"); // Violations //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.violation"); // SAN Path Violations //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.sa.violation.event"); // Violation Event //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.sa.violation.impact.details"); // Violations Impact Details //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.micro.applications"); // Applications //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.host"); // Hosts //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.datastore"); // Data Stores //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.performance.center.datastore"); // Data Store Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.vm"); // Virtual Machines //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.hostvirtualization.vm.utilization"); // VM Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.virtualMachineDisks"); // VMDKs //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.inventory.virtualMachineDisks.performance");// VMDK Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.pm.reservation"); // Reservations //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.pm.reservation.violations"); // Reservation Violations //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.tasks.errors"); // Task List Errors //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.tasks.violations"); // Task Future Violations //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.affected.paths"); // Migrations Affected Paths //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.migration.impact"); // Migrations Impact //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.migration.qa"); // Migration Quality Assurance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.migration.switches"); // Migrated Switches //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.perf.micro.traffic.analyzer"); // Switch Port Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.performance.dialog.traffic.analyzer");// Switch Port Performance //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.performance.port.micro"); // Switch port performance micro //$NON-NLS-1$ MICRO_VIEW_ORDER.add("views.switch.performance.port.alert"); // Switch port performance alert //$NON-NLS-1$ }; /* Desired order of all center views. Each time we build a set of center views we will sort them based on this list for consistency. */ private static final List CENTER_VIEW_ORDER = new ArrayList(); static { CENTER_VIEW_ORDER.add("views.performance.dialog.traffic.analyzer");// Switch Port Performance //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.topology"); // Inventory Topology //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.performance.port.balance.topology"); // Port Balance Topology //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.host"); // Hosts //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.performance.host.micro"); // Host Performance //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.virtualMachineDisks"); // VMDKs //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.virtualMachineDisks.performance");// VMDK Performance //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.vm"); // Virtual Machines //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.hostvirtualization.vm.utilization.center");// Virtual Machine Performance //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.hostvirtualization.vm.utilization"); // Virtual Machine Performance //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.micro.volume.storage"); // Volumes //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.si.micro.virtualVolume"); // Virtual Volumes //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.micro.internal.volume"); // Internal Volumes //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.si.micro.virtualInternalVolume"); // Virtual Internal Volumes //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.micro.backend.volume"); // Backend Volumes //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.inventory.micro.disk"); // Disks //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.tasks.actions"); // Tasks //$NON-NLS-1$ CENTER_VIEW_ORDER.add("views.switch.performance.port.violation"); // Switch port violations //$NON-NLS-1$ }; private static final Comparator MICRO_VIEW_ADAPTER_COMPARATOR = new Comparator() { @Override public int compare(ViewAdapter a1, ViewAdapter a2) { int i1 = MICRO_VIEW_ORDER.indexOf(a1.getView().getName()); int i2 = MICRO_VIEW_ORDER.indexOf(a2.getView().getName()); if(i1 == -1) { throw new IllegalArgumentException("View '" + a1.getView().getName() + "' does not exist in ViewSorter's MICRO_VIEW_ORDER list. Please add it."); //$NON-NLS-1$ //$NON-NLS-2$ } if(i2 == -1) { throw new IllegalArgumentException("View '" + a2.getView().getName() + "' does not exist in ViewSorter's MICRO_VIEW_ORDER list. Please add it."); //$NON-NLS-1$ //$NON-NLS-2$ } return(i1 - i2); } }; private static final Comparator CENTER_VIEW_ADAPTER_COMPARATOR = new Comparator() { @Override public int compare(ViewAdapter a1, ViewAdapter a2) { int i1 = CENTER_VIEW_ORDER.indexOf(a1.getView().getName()); int i2 = CENTER_VIEW_ORDER.indexOf(a2.getView().getName()); if(i1 == -1) { throw new IllegalArgumentException("View '" + a1.getView().getName() + "' does not exist in ViewSorter's CENTER_VIEW_ORDER list. Please add it."); //$NON-NLS-1$ //$NON-NLS-2$ } if(i2 == -1) { throw new IllegalArgumentException("View '" + a2.getView().getName() + "' does not exist in ViewSorter's CENTER_VIEW_ORDER list. Please add it."); //$NON-NLS-1$ //$NON-NLS-2$ } return(i1 - i2); } }; /** * Sorts the list of microview adapters in place based on the global sort order. * * @param microViewAdapters the list of microview adapters to sort. */ public static void sortMicroViewAdapters(List microViewAdapters) { Collections.sort(microViewAdapters, MICRO_VIEW_ADAPTER_COMPARATOR); } /** * Sorts the list of center view adapters in place based on the global sort order. * * @param centerViewAdapters the list of microview adapters to sort. */ public static void sortCenterViewAdapters(List centerViewAdapters) { Collections.sort(centerViewAdapters, CENTER_VIEW_ADAPTER_COMPARATOR); } }