sysmodelmgr/com.symbian.smt.gui/src/com/symbian/smt/gui/smtwidgets/resources/ResourcesWidget.java
changeset 0 522a326673b6
equal deleted inserted replaced
-1:000000000000 0:522a326673b6
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 package com.symbian.smt.gui.smtwidgets.resources;
       
    17 
       
    18 import java.util.ArrayList;
       
    19 import java.util.HashMap;
       
    20 
       
    21 import org.eclipse.jface.viewers.CheckStateChangedEvent;
       
    22 import org.eclipse.jface.viewers.CheckboxTableViewer;
       
    23 import org.eclipse.jface.viewers.ICheckStateListener;
       
    24 import org.eclipse.jface.viewers.ILabelProvider;
       
    25 import org.eclipse.jface.viewers.ILabelProviderListener;
       
    26 import org.eclipse.jface.viewers.ISelectionChangedListener;
       
    27 import org.eclipse.jface.viewers.IStructuredContentProvider;
       
    28 import org.eclipse.jface.viewers.IStructuredSelection;
       
    29 import org.eclipse.jface.viewers.ITableLabelProvider;
       
    30 import org.eclipse.jface.viewers.ListViewer;
       
    31 import org.eclipse.jface.viewers.SelectionChangedEvent;
       
    32 import org.eclipse.jface.viewers.StructuredSelection;
       
    33 import org.eclipse.jface.viewers.Viewer;
       
    34 import org.eclipse.swt.SWT;
       
    35 import org.eclipse.swt.custom.SashForm;
       
    36 import org.eclipse.swt.events.SelectionAdapter;
       
    37 import org.eclipse.swt.events.SelectionEvent;
       
    38 import org.eclipse.swt.graphics.Image;
       
    39 import org.eclipse.swt.layout.FillLayout;
       
    40 import org.eclipse.swt.layout.GridData;
       
    41 import org.eclipse.swt.layout.GridLayout;
       
    42 import org.eclipse.swt.layout.RowData;
       
    43 import org.eclipse.swt.layout.RowLayout;
       
    44 import org.eclipse.swt.widgets.Button;
       
    45 import org.eclipse.swt.widgets.Composite;
       
    46 import org.eclipse.swt.widgets.Label;
       
    47 import org.eclipse.swt.widgets.List;
       
    48 import org.eclipse.swt.widgets.Table;
       
    49 
       
    50 import com.symbian.smt.gui.Helper;
       
    51 import com.symbian.smt.gui.ResourcesEnums;
       
    52 
       
    53 public class ResourcesWidget extends Composite {
       
    54 
       
    55 	/**
       
    56 	 * This is the content provider for the list of resource types.
       
    57 	 * 
       
    58 	 * @author barbararosi-schwartz
       
    59 	 */
       
    60 	private class ResourceFilesContentProvider implements
       
    61 			IStructuredContentProvider {
       
    62 
       
    63 		public void dispose() {
       
    64 		}
       
    65 
       
    66 		@SuppressWarnings("unchecked")
       
    67 		public Object[] getElements(Object inputElement) {
       
    68 			return ResourcesWidgetHelper
       
    69 					.toArrayOfCheckableResourceFilenames((java.util.List<CheckableResourceFilename>) inputElement);
       
    70 		}
       
    71 
       
    72 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
       
    73 		}
       
    74 	}
       
    75 
       
    76 	/**
       
    77 	 * This is the label provider for the list of of resource types.
       
    78 	 * 
       
    79 	 * @author barbararosi-schwartz
       
    80 	 */
       
    81 	private class ResourceFilesLabelProvider implements ITableLabelProvider {
       
    82 
       
    83 		public void addListener(ILabelProviderListener listener) {
       
    84 		}
       
    85 
       
    86 		public void dispose() {
       
    87 		}
       
    88 
       
    89 		public Image getColumnImage(Object element, int columnIndex) {
       
    90 			return null;
       
    91 		}
       
    92 
       
    93 		public String getColumnText(Object element, int columnIndex) {
       
    94 			CheckableResourceFilename crf = (CheckableResourceFilename) element;
       
    95 
       
    96 			return (columnIndex == 0) ? crf.getFilename() : null;
       
    97 		}
       
    98 
       
    99 		public boolean isLabelProperty(Object element, String property) {
       
   100 			return false;
       
   101 		}
       
   102 
       
   103 		public void removeListener(ILabelProviderListener listener) {
       
   104 		}
       
   105 
       
   106 	}
       
   107 
       
   108 	/**
       
   109 	 * This is the content provider for the list of resource types.
       
   110 	 * 
       
   111 	 * @author barbararosi-schwartz
       
   112 	 */
       
   113 	private class ResourceTypesContentProvider implements
       
   114 			IStructuredContentProvider {
       
   115 
       
   116 		public void dispose() {
       
   117 		}
       
   118 
       
   119 		public Object[] getElements(Object inputElement) {
       
   120 			return (ResourcesEnums[]) inputElement;
       
   121 		}
       
   122 
       
   123 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
       
   124 		}
       
   125 	}
       
   126 
       
   127 	/**
       
   128 	 * This is the label provider for the list of of resource types.
       
   129 	 * 
       
   130 	 * @author barbararosi-schwartz
       
   131 	 */
       
   132 	private class ResourceTypesLabelProvider implements ILabelProvider {
       
   133 
       
   134 		public void addListener(ILabelProviderListener listener) {
       
   135 		}
       
   136 
       
   137 		public void dispose() {
       
   138 		}
       
   139 
       
   140 		public Image getImage(Object element) {
       
   141 			return null;
       
   142 		}
       
   143 
       
   144 		public String getText(Object element) {
       
   145 			return ((ResourcesEnums) element).arg();
       
   146 		}
       
   147 
       
   148 		public boolean isLabelProperty(Object element, String property) {
       
   149 			return false;
       
   150 		}
       
   151 
       
   152 		public void removeListener(ILabelProviderListener listener) {
       
   153 		}
       
   154 
       
   155 	}
       
   156 
       
   157 	/**
       
   158 	 * The Map that caches all defined resource files, keyed by the
       
   159 	 * ResourcesEnums enums.
       
   160 	 */
       
   161 	private final HashMap<ResourcesEnums, java.util.List<CheckableResourceFilename>> resourceFilesMap = new HashMap<ResourcesEnums, java.util.List<CheckableResourceFilename>>();
       
   162 
       
   163 	/**
       
   164 	 * The viewer associated with the Resource Files List widget.
       
   165 	 */
       
   166 	private CheckboxTableViewer resourceFilesViewer;
       
   167 
       
   168 	/**
       
   169 	 * The viewer associated with the Resource Types List widget.
       
   170 	 */
       
   171 	private ListViewer resourceTypesViewer;
       
   172 
       
   173 	/**
       
   174 	 * Creates a ResourcesWidget composite object
       
   175 	 * 
       
   176 	 * @return void
       
   177 	 */
       
   178 	public ResourcesWidget(final Composite parent, int style) {
       
   179 		super(parent, style);
       
   180 
       
   181 		initialiseMaps();
       
   182 		this.setLayout(new FillLayout());
       
   183 
       
   184 		// The Composite that contains all widgets
       
   185 		final Composite gridLayoutComposite = new Composite(this, SWT.NONE);
       
   186 		final GridLayout gridLayout = new GridLayout();
       
   187 		gridLayout.numColumns = 1;
       
   188 
       
   189 		gridLayoutComposite.setLayout(gridLayout);
       
   190 
       
   191 		// The SashForm that contains the resource types and resource files
       
   192 		// widgets
       
   193 		// side by side
       
   194 		SashForm sash = new SashForm(gridLayoutComposite, SWT.HORIZONTAL);
       
   195 		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
       
   196 
       
   197 		sash.setLayoutData(gd);
       
   198 		createResourceTypesComposite(sash);
       
   199 		createResourceFilesComposite(sash);
       
   200 		sash.setWeights(new int[] { 30, 70 });
       
   201 		createButtonsComposite(gridLayoutComposite);
       
   202 	}
       
   203 
       
   204 	private void addAddResourceButton(Composite parent) {
       
   205 		// The "Add" button
       
   206 		final Button addResourceFileButton = new Button(parent, SWT.NONE);
       
   207 		RowData rd = new RowData();
       
   208 		rd.width = 75;
       
   209 
       
   210 		addResourceFileButton.setLayoutData(rd);
       
   211 
       
   212 		// The action that backs the "Add" button
       
   213 		final AddResourceFileAction addResourceFileAction = new AddResourceFileAction(
       
   214 				addResourceFileButton, resourceFilesViewer, resourceFilesMap,
       
   215 				resourceTypesViewer);
       
   216 
       
   217 		// When button is pressed, listener invokes the action's run() method,
       
   218 		// then ensures that the newly added file is checked, guaranteeing that
       
   219 		// all rules around multiple checked files are respected.
       
   220 		// Finally refreshes the List of assigned options and set the selection
       
   221 		// appropriately.
       
   222 		// If the newly added file failed validation during the action's run()
       
   223 		// method,
       
   224 		// none of the operations above is taken and all is left as it was prior
       
   225 		// to
       
   226 		// the request to add a new file.
       
   227 		addResourceFileButton.addSelectionListener(new SelectionAdapter() {
       
   228 			public void widgetSelected(final SelectionEvent e) {
       
   229 				addResourceFileAction.run();
       
   230 				resourceFilesViewer.refresh();
       
   231 
       
   232 				String newFileLocation = addResourceFileAction
       
   233 						.getNewFileLocation();
       
   234 
       
   235 				// newFile could be null if an error was detected in the
       
   236 				// validations
       
   237 				// performed in the action's run() method.
       
   238 				if (newFileLocation != null) {
       
   239 					ResourcesEnums type = ResourcesWidgetHelper
       
   240 							.getSelectedResourceType(resourceTypesViewer);
       
   241 					CheckableResourceFilename crf = ResourcesWidgetHelper
       
   242 							.filename2checkableFilename(newFileLocation, type,
       
   243 									resourceFilesMap);
       
   244 
       
   245 					handleMultipleCheckRules(crf);
       
   246 
       
   247 					StructuredSelection oldSel = (StructuredSelection) resourceFilesViewer
       
   248 							.getSelection();
       
   249 
       
   250 					StructuredSelection newSel = (newFileLocation == null) ? oldSel
       
   251 							: new StructuredSelection(newFileLocation);
       
   252 
       
   253 					resourceFilesViewer.setSelection(newSel);
       
   254 				}
       
   255 			}
       
   256 		});
       
   257 	}
       
   258 
       
   259 	private void addMoveDownResourceButton(Composite parent) {
       
   260 		// The "Move Down" button
       
   261 		final Button moveResourceFileDownButton = new Button(parent, SWT.NONE);
       
   262 		RowData rd = new RowData();
       
   263 		rd.width = 75;
       
   264 
       
   265 		moveResourceFileDownButton.setLayoutData(rd);
       
   266 
       
   267 		// The action that backs the "Move Down" button
       
   268 		final MoveResourceFileDownAction moveResourceFileDownAction = new MoveResourceFileDownAction(
       
   269 				moveResourceFileDownButton, resourceFilesViewer,
       
   270 				resourceFilesMap, resourceTypesViewer);
       
   271 
       
   272 		// When button is pressed, listener invokes the action's run() method,
       
   273 		// then refreshes the List of assigned options and set the selection
       
   274 		// appropriately
       
   275 		moveResourceFileDownButton.addSelectionListener(new SelectionAdapter() {
       
   276 			public void widgetSelected(final SelectionEvent e) {
       
   277 				moveResourceFileDownAction.run();
       
   278 				resourceFilesViewer.refresh();
       
   279 
       
   280 				StructuredSelection newSel = new StructuredSelection(
       
   281 						moveResourceFileDownAction.getMovedCheckableFilename());
       
   282 
       
   283 				resourceFilesViewer.setSelection(newSel);
       
   284 			}
       
   285 		});
       
   286 	}
       
   287 
       
   288 	private void addMoveUpResourceButton(Composite parent) {
       
   289 		// The "Move Up" button
       
   290 		final Button moveResourceFileUpButton = new Button(parent, SWT.NONE);
       
   291 		RowData rd = new RowData();
       
   292 		rd.width = 75;
       
   293 
       
   294 		moveResourceFileUpButton.setLayoutData(rd);
       
   295 
       
   296 		// The action that backs the "Move Up" button
       
   297 		final MoveResourceFileUpAction moveResourceFileUpAction = new MoveResourceFileUpAction(
       
   298 				moveResourceFileUpButton, resourceFilesViewer,
       
   299 				resourceFilesMap, resourceTypesViewer);
       
   300 
       
   301 		// When button is pressed, listener invokes the action's run() method,
       
   302 		// then refreshes the List of assigned options and set the selection
       
   303 		// appropriately
       
   304 		moveResourceFileUpButton.addSelectionListener(new SelectionAdapter() {
       
   305 			public void widgetSelected(final SelectionEvent e) {
       
   306 				moveResourceFileUpAction.run();
       
   307 				resourceFilesViewer.refresh();
       
   308 
       
   309 				StructuredSelection newSel = new StructuredSelection(
       
   310 						moveResourceFileUpAction.getMovedCheckableFilename());
       
   311 
       
   312 				resourceFilesViewer.setSelection(newSel);
       
   313 			}
       
   314 		});
       
   315 
       
   316 	}
       
   317 
       
   318 	private void addRemoveResourceButton(Composite parent) {
       
   319 		// The "Remove" button
       
   320 		final Button removeResourceFileButton = new Button(parent, SWT.NONE);
       
   321 		RowData rd = new RowData();
       
   322 		rd.width = 75;
       
   323 
       
   324 		removeResourceFileButton.setLayoutData(rd);
       
   325 
       
   326 		// The action that backs the "Remove" button
       
   327 		final RemoveResourceFileAction removeResourceFileAction = new RemoveResourceFileAction(
       
   328 				removeResourceFileButton, resourceFilesViewer,
       
   329 				resourceFilesMap, resourceTypesViewer);
       
   330 
       
   331 		// When button is pressed, listener invokes the action's run() method,
       
   332 		// then refreshes the List of assigned options and set the selection
       
   333 		// appropriately
       
   334 		removeResourceFileButton.addSelectionListener(new SelectionAdapter() {
       
   335 			public void widgetSelected(SelectionEvent e) {
       
   336 				removeResourceFileAction.run();
       
   337 				resourceFilesViewer.refresh();
       
   338 
       
   339 				Object firstElement = resourceFilesViewer.getElementAt(0);
       
   340 				StructuredSelection ssel = (firstElement == null) ? new StructuredSelection(
       
   341 						StructuredSelection.EMPTY)
       
   342 						: new StructuredSelection(firstElement);
       
   343 
       
   344 				resourceFilesViewer.setSelection(ssel);
       
   345 			}
       
   346 		});
       
   347 	}
       
   348 
       
   349 	private void checkFilesInResourceFilesTable(String[] filenames,
       
   350 			ResourcesEnums resourceType) {
       
   351 		if (filenames == null) {
       
   352 			throw new IllegalArgumentException(
       
   353 					"Argument filenames cannot be null.");
       
   354 		}
       
   355 
       
   356 		java.util.List<String> listOfFilenames = Helper
       
   357 				.toListOfStrings(filenames);
       
   358 		java.util.List<CheckableResourceFilename> checkableFilenames = resourceFilesMap
       
   359 				.get(resourceType);
       
   360 
       
   361 		if (checkableFilenames == null) {
       
   362 			throw new IllegalArgumentException(
       
   363 					"Could not find any elements of type [" + resourceType
       
   364 							+ "] in resourceFilesMap.");
       
   365 		}
       
   366 
       
   367 		CheckableResourceFilename[] viewerElementsToBeChecked = new CheckableResourceFilename[filenames.length];
       
   368 		int i = 0;
       
   369 
       
   370 		for (String filename : listOfFilenames) {
       
   371 
       
   372 			CheckableResourceFilename checkableFilename = ResourcesWidgetHelper
       
   373 					.filename2checkableFilename(filename, resourceType,
       
   374 							resourceFilesMap);
       
   375 
       
   376 			checkableFilename.setChecked(true);
       
   377 
       
   378 			viewerElementsToBeChecked[i] = checkableFilename;
       
   379 			i++;
       
   380 		}
       
   381 		
       
   382 		IStructuredSelection ssel = (IStructuredSelection) resourceTypesViewer.getSelection();
       
   383 		if (!ssel.isEmpty()) {
       
   384 			ResourcesEnums selectedType = (ResourcesEnums) ssel.getFirstElement();
       
   385 			if (selectedType.equals(resourceType)) {
       
   386 				resourceFilesViewer.setCheckedElements(viewerElementsToBeChecked);
       
   387 			}
       
   388 		}
       
   389 		
       
   390 		
       
   391 	}
       
   392 
       
   393 	private void createButtonsComposite(Composite parent) {
       
   394 		// The Composite that contains all buttons in a horizontal stack
       
   395 		final Composite buttonsComposite = new Composite(parent, SWT.NONE);
       
   396 		final RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
       
   397 		rowLayout.spacing = 5;
       
   398 		rowLayout.wrap = false;
       
   399 		rowLayout.fill = true;
       
   400 
       
   401 		buttonsComposite.setLayout(rowLayout);
       
   402 
       
   403 		GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, false,
       
   404 				1, 1);
       
   405 
       
   406 		buttonsComposite.setLayoutData(gd);
       
   407 		addAddResourceButton(buttonsComposite);
       
   408 		addRemoveResourceButton(buttonsComposite);
       
   409 		addMoveUpResourceButton(buttonsComposite);
       
   410 		addMoveDownResourceButton(buttonsComposite);
       
   411 	}
       
   412 
       
   413 	private void createResourceFilesComposite(SashForm sash) {
       
   414 		// The Composite that contains the resource files table, along with a
       
   415 		// label
       
   416 		Composite resourceFilesComposite = new Composite(sash, SWT.NONE);
       
   417 		GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, true, 1, 1);
       
   418 
       
   419 		resourceFilesComposite.setLayoutData(gd);
       
   420 		resourceFilesComposite.setLayout(new GridLayout());
       
   421 
       
   422 		Label label = new Label(resourceFilesComposite, SWT.NONE);
       
   423 		gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1);
       
   424 
       
   425 		label.setLayoutData(gd);
       
   426 		label.setText("Resource Files");
       
   427 
       
   428 		// The Table that contains all assigned resource files for the selected
       
   429 		// resource type
       
   430 		final Table table = new Table(resourceFilesComposite, SWT.BORDER
       
   431 				| SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.CHECK
       
   432 				| SWT.FULL_SELECTION);
       
   433 		gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
       
   434 
       
   435 		table.setLayoutData(gd);
       
   436 
       
   437 		// The resource type viewer associated with the list
       
   438 		resourceFilesViewer = new CheckboxTableViewer(table);
       
   439 
       
   440 		resourceFilesViewer
       
   441 				.setContentProvider(new ResourceFilesContentProvider());
       
   442 		resourceFilesViewer.setLabelProvider(new ResourceFilesLabelProvider());
       
   443 
       
   444 		resourceFilesViewer.addCheckStateListener(new ICheckStateListener() {
       
   445 
       
   446 			// When the user changed the checked state of the checkbox in the
       
   447 			// table, set
       
   448 			// or unset the isChecked attribute in the corresponding
       
   449 			// CheckableResourceFilename object
       
   450 			public void checkStateChanged(CheckStateChangedEvent event) {
       
   451 				CheckableResourceFilename checkableFilename = (CheckableResourceFilename) event
       
   452 						.getElement();
       
   453 				boolean isSelected = event.getChecked();
       
   454 
       
   455 				if (isSelected) {
       
   456 					handleMultipleCheckRules(checkableFilename);
       
   457 				} else {
       
   458 					handleNoCheckRules(checkableFilename);
       
   459 				}
       
   460 			}
       
   461 
       
   462 		});
       
   463 	}
       
   464 
       
   465 	private void createResourceTypesComposite(SashForm sash) {
       
   466 		// The Composite that contains the resource types list, along with a
       
   467 		// label
       
   468 		Composite resourceTypesComposite = new Composite(sash, SWT.NONE);
       
   469 		GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, true, 1, 1);
       
   470 
       
   471 		resourceTypesComposite.setLayoutData(gd);
       
   472 		resourceTypesComposite.setLayout(new GridLayout());
       
   473 
       
   474 		Label l = new Label(resourceTypesComposite, SWT.NONE);
       
   475 		gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1);
       
   476 
       
   477 		l.setLayoutData(gd);
       
   478 		l.setText("Resource Types");
       
   479 
       
   480 		// The List that contains all possible resource types
       
   481 		final List list = new List(resourceTypesComposite, SWT.BORDER
       
   482 				| SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE);
       
   483 		gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
       
   484 
       
   485 		list.setLayoutData(gd);
       
   486 
       
   487 		// The resource type viewer associated with the list
       
   488 		resourceTypesViewer = new ListViewer(list);
       
   489 
       
   490 		resourceTypesViewer
       
   491 				.setContentProvider(new ResourceTypesContentProvider());
       
   492 		resourceTypesViewer.setLabelProvider(new ResourceTypesLabelProvider());
       
   493 		resourceTypesViewer.setInput(ResourcesEnums.values());
       
   494 
       
   495 		resourceTypesViewer
       
   496 				.addSelectionChangedListener(new ISelectionChangedListener() {
       
   497 					public void selectionChanged(SelectionChangedEvent event) {
       
   498 						IStructuredSelection ssel = (IStructuredSelection) event
       
   499 								.getSelection();
       
   500 						if (ssel.isEmpty()) {
       
   501 							return;
       
   502 						}
       
   503 						ResourcesEnums selectedType = (ResourcesEnums) ssel.getFirstElement();
       
   504 
       
   505 						resourceFilesViewer.setInput(ResourcesWidgetHelper
       
   506 								.getCheckableResourceFilenames(selectedType,
       
   507 										resourceFilesMap));
       
   508 						
       
   509 						resourceFilesViewer
       
   510 								.setCheckedElements(ResourcesWidgetHelper
       
   511 										.getCheckedResourceFilenames(
       
   512 												selectedType, resourceFilesMap));
       
   513 					}
       
   514 				});
       
   515 	}
       
   516 
       
   517 	@Override
       
   518 	public void dispose() {
       
   519 		resourceFilesMap.clear();
       
   520 		super.dispose();
       
   521 	}
       
   522 
       
   523 	/**
       
   524 	 * Returns the shapes file or an empty string if no shapes file has been
       
   525 	 * specified
       
   526 	 * 
       
   527 	 * @return String
       
   528 	 */
       
   529 	public String[] getBorderShapesFiles() {
       
   530 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.BORDER_SHAPES,
       
   531 				resourceFilesMap);
       
   532 	}
       
   533 
       
   534 	/**
       
   535 	 * Returns the shapes file or an empty string if no shapes file has been
       
   536 	 * specified
       
   537 	 * 
       
   538 	 * @return String
       
   539 	 */
       
   540 	public String[] getBorderStylesFiles() {
       
   541 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.BORDER_STYLES,
       
   542 				resourceFilesMap);
       
   543 	}
       
   544 
       
   545 	/**
       
   546 	 * Returns the shapes file or an empty string if no shapes file has been
       
   547 	 * specified
       
   548 	 * 
       
   549 	 * @return String
       
   550 	 */
       
   551 	public String[] getColoursFiles() {
       
   552 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.COLOURS,
       
   553 				resourceFilesMap);
       
   554 	}
       
   555 
       
   556 	/**
       
   557 	 * Returns the shapes file or an empty string if no shapes file has been
       
   558 	 * specified
       
   559 	 * 
       
   560 	 * @return String
       
   561 	 */
       
   562 	public String[] getDependenciesFiles() {
       
   563 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.DEPENDENCIES,
       
   564 				resourceFilesMap);
       
   565 	}
       
   566 
       
   567 	/**
       
   568 	 * Returns the shapes file or an empty string if no shapes file has been
       
   569 	 * specified
       
   570 	 * 
       
   571 	 * @return String
       
   572 	 */
       
   573 	public String[] getLevelsFiles() {
       
   574 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.LEVELS,
       
   575 				resourceFilesMap);
       
   576 	}
       
   577 
       
   578 	/**
       
   579 	 * Returns the shapes file or an empty string if no shapes file has been
       
   580 	 * specified
       
   581 	 * 
       
   582 	 * @return String
       
   583 	 */
       
   584 	public String[] getLocalisationFiles() {
       
   585 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.LOCALISATION,
       
   586 				resourceFilesMap);
       
   587 	}
       
   588 
       
   589 	/**
       
   590 	 * Returns the shapes file or an empty string if no shapes file has been
       
   591 	 * specified
       
   592 	 * 
       
   593 	 * @return String
       
   594 	 */
       
   595 	public String[] getPatternsFiles() {
       
   596 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.PATTERNS,
       
   597 				resourceFilesMap);
       
   598 	}
       
   599 
       
   600 	/**
       
   601 	 * Returns the shapes file or an empty string if no shapes file has been
       
   602 	 * specified
       
   603 	 * 
       
   604 	 * @return String
       
   605 	 */
       
   606 	public String[] getS12XmlFiles() {
       
   607 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.S12_XML,
       
   608 				resourceFilesMap);
       
   609 	}
       
   610 
       
   611 	/**
       
   612 	 * Returns the border shapes file or an empty string if no border shapes
       
   613 	 * file has been specified
       
   614 	 * 
       
   615 	 * @return String
       
   616 	 */
       
   617 	public String[] getSelectedBorderShapesFiles() {
       
   618 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   619 				ResourcesEnums.BORDER_SHAPES, resourceFilesMap);
       
   620 	}
       
   621 
       
   622 	/**
       
   623 	 * Returns the border styles file or an empty string if no border styles
       
   624 	 * file has been specified
       
   625 	 * 
       
   626 	 * @return String
       
   627 	 */
       
   628 	public String[] getSelectedBorderStylesFiles() {
       
   629 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   630 				ResourcesEnums.BORDER_STYLES, resourceFilesMap);
       
   631 	}
       
   632 
       
   633 	/**
       
   634 	 * Returns the colours file or an empty string if no colours file has been
       
   635 	 * specified
       
   636 	 * 
       
   637 	 * @return String
       
   638 	 */
       
   639 	public String[] getSelectedColoursFiles() {
       
   640 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   641 				ResourcesEnums.COLOURS, resourceFilesMap);
       
   642 	}
       
   643 
       
   644 	/**
       
   645 	 * Returns the dependencies file or an empty string if no dependencies file
       
   646 	 * has been specified
       
   647 	 * 
       
   648 	 * @return String
       
   649 	 */
       
   650 	public String[] getSelectedDependenciesFiles() {
       
   651 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   652 				ResourcesEnums.DEPENDENCIES, resourceFilesMap);
       
   653 	}
       
   654 
       
   655 	/**
       
   656 	 * Returns the levels file or an empty string if no levels file has been
       
   657 	 * specified
       
   658 	 * 
       
   659 	 * @return String
       
   660 	 */
       
   661 	public String[] getSelectedLevelsFiles() {
       
   662 		return ResourcesWidgetHelper.getCheckedFilenames(ResourcesEnums.LEVELS,
       
   663 				resourceFilesMap);
       
   664 	}
       
   665 
       
   666 	/**
       
   667 	 * Returns the localisation file or an empty string if no localisation file
       
   668 	 * has been specified
       
   669 	 * 
       
   670 	 * @return String
       
   671 	 */
       
   672 	public String[] getSelectedLocalisationFiles() {
       
   673 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   674 				ResourcesEnums.LOCALISATION, resourceFilesMap);
       
   675 	}
       
   676 
       
   677 	/**
       
   678 	 * Returns the patterns file or an empty string if no patterns file has been
       
   679 	 * specified
       
   680 	 * 
       
   681 	 * @return String
       
   682 	 */
       
   683 	public String[] getSelectedPatternsFiles() {
       
   684 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   685 				ResourcesEnums.PATTERNS, resourceFilesMap);
       
   686 	}
       
   687 
       
   688 	/**
       
   689 	 * Returns the patterns file or an empty string if no patterns file has been
       
   690 	 * specified
       
   691 	 * 
       
   692 	 * @return String
       
   693 	 */
       
   694 	public String[] getSelectedS12XmlFiles() {
       
   695 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   696 				ResourcesEnums.S12_XML, resourceFilesMap);
       
   697 	}
       
   698 
       
   699 	/**
       
   700 	 * Returns the shapes file or an empty string if no shapes file has been
       
   701 	 * specified
       
   702 	 * 
       
   703 	 * @return String
       
   704 	 */
       
   705 	public String[] getSelectedShapesFiles() {
       
   706 		return ResourcesWidgetHelper.getCheckedFilenames(ResourcesEnums.SHAPES,
       
   707 				resourceFilesMap);
       
   708 	}
       
   709 
       
   710 	/**
       
   711 	 * Returns the system info file or an empty string if no system info file
       
   712 	 * has been specified
       
   713 	 * 
       
   714 	 * @return String
       
   715 	 */
       
   716 	public String[] getSelectedSystemInfoFiles() {
       
   717 		return ResourcesWidgetHelper.getCheckedFilenames(
       
   718 				ResourcesEnums.SYSTEM_INFO, resourceFilesMap);
       
   719 	}
       
   720 
       
   721 	/**
       
   722 	 * Returns the shapes file or an empty string if no shapes file has been
       
   723 	 * specified
       
   724 	 * 
       
   725 	 * @return String
       
   726 	 */
       
   727 	public String[] getShapesFiles() {
       
   728 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.SHAPES,
       
   729 				resourceFilesMap);
       
   730 	}
       
   731 
       
   732 	/**
       
   733 	 * Returns the shapes file or an empty string if no shapes file has been
       
   734 	 * specified
       
   735 	 * 
       
   736 	 * @return String
       
   737 	 */
       
   738 	public String[] getSystemInfoFiles() {
       
   739 		return ResourcesWidgetHelper.getFilenames(ResourcesEnums.SYSTEM_INFO,
       
   740 				resourceFilesMap);
       
   741 	}
       
   742 
       
   743 	/**
       
   744 	 * Checks the designated resource file and sets its <code>isChecked</code>
       
   745 	 * attribute to true. Handles business rules around the acceptability of
       
   746 	 * having multiple checked files.
       
   747 	 * <p>
       
   748 	 * The rules are as follows:
       
   749 	 * <ul>
       
   750 	 * <li>If resource type is DEPENDENCIES or SHAPES, only allow one check at a
       
   751 	 * time: uncheck all other files and remove them from
       
   752 	 * <code>selectedResourceFilesMap</code></li>
       
   753 	 * <li>In all other cases, allow multiple checks</li>
       
   754 	 * </ul>
       
   755 	 * </p>
       
   756 	 * 
       
   757 	 * @param resourceFile
       
   758 	 *            the CheckableResourceFilename object that has been checked by
       
   759 	 *            the user
       
   760 	 */
       
   761 	private void handleMultipleCheckRules(
       
   762 			CheckableResourceFilename checkedCheckableFilename) {
       
   763 		ResourcesEnums selectedResourceType = ResourcesWidgetHelper
       
   764 				.getSelectedResourceType(resourceTypesViewer);
       
   765 		java.util.List<CheckableResourceFilename> checkableFilenames = ResourcesWidgetHelper
       
   766 				.getCheckableResourceFilenames(selectedResourceType,
       
   767 						resourceFilesMap);
       
   768 
       
   769 		checkedCheckableFilename.setChecked(true);
       
   770 
       
   771 		switch (selectedResourceType) {
       
   772 		// Only one file can be checked at a time, therefore uncheck all others
       
   773 		case DEPENDENCIES:
       
   774 		case SHAPES:
       
   775 			for (CheckableResourceFilename checkableFilename : checkableFilenames) {
       
   776 				if (!checkableFilename.equals(checkedCheckableFilename)) {
       
   777 					checkableFilename.setChecked(false);
       
   778 				}
       
   779 			}
       
   780 
       
   781 			resourceFilesViewer
       
   782 					.setCheckedElements(new CheckableResourceFilename[] { checkedCheckableFilename });
       
   783 			break;
       
   784 
       
   785 		// If multiple files are checked and they contain the same elements,
       
   786 		// prevent checking from happening as it will generate an error in
       
   787 		// the build. Produce an explanatory error dialog.
       
   788 		case BORDER_SHAPES:
       
   789 		case PATTERNS:
       
   790 			// TODO:BRS:This piece of code is unfinished. If it is required to check 
       
   791 			// that there are no duplicate items across 
       
   792 			// the defined XML files, check similar behaviour in ResourceFileValidator.
       
   793 			// If ok
       
   794 			// resourceFilesViewer.setChecked(resourceFile, true);
       
   795 			// selectedResourceFiles.add(resourceFile);
       
   796 			// else
       
   797 			// MessageDialog.openError("Checked files contain the same element and the process will fail.\n"
       
   798 			// +
       
   799 			// "Please remove duplicate elements or uncheck one or more of the other files.");
       
   800 			// resourceFilesViewer.setChecked(resourceFile, false);
       
   801 
       
   802 			resourceFilesViewer.setChecked(checkedCheckableFilename, true);
       
   803 			break;
       
   804 
       
   805 		// If "Auto" is checked, uncheck everything else. If another option is
       
   806 		// checked, uncheck "Auto".
       
   807 		case LEVELS:
       
   808 			if (checkedCheckableFilename.getFilename().equals("Auto")) {
       
   809 				for (CheckableResourceFilename checkableFilename : checkableFilenames) {
       
   810 					if (!checkableFilename.equals(checkedCheckableFilename)) {
       
   811 						checkableFilename.setChecked(false);
       
   812 					}
       
   813 				}
       
   814 
       
   815 				resourceFilesViewer
       
   816 						.setCheckedElements(new CheckableResourceFilename[] { checkedCheckableFilename });
       
   817 			} else {
       
   818 				resourceFilesViewer.setChecked(checkedCheckableFilename, true);
       
   819 
       
   820 				CheckableResourceFilename autocfn = ResourcesWidgetHelper
       
   821 						.filename2checkableFilename("Auto",
       
   822 								ResourcesEnums.LEVELS, resourceFilesMap);
       
   823 
       
   824 				if (autocfn.isChecked()) {
       
   825 					autocfn.setChecked(false);
       
   826 					resourceFilesViewer.setChecked(autocfn, false);
       
   827 				}
       
   828 			}
       
   829 
       
   830 			break;
       
   831 
       
   832 		// No special rules, proceed with the operation.
       
   833 		case BORDER_STYLES:
       
   834 		case COLOURS:
       
   835 		case LOCALISATION:
       
   836 		case S12_XML:
       
   837 		case SYSTEM_INFO:
       
   838 			resourceFilesViewer.setChecked(checkedCheckableFilename, true);
       
   839 			break;
       
   840 
       
   841 		default:
       
   842 			throw new IllegalArgumentException("Unknown resource type ["
       
   843 					+ selectedResourceType + "]");
       
   844 		}
       
   845 	}
       
   846 
       
   847 	/**
       
   848 	 * Unchecks the designated CheckableResourceFilename object. Handles
       
   849 	 * business rules around the acceptability of having no checked files.
       
   850 	 * <p>
       
   851 	 * The rules are as follows:
       
   852 	 * <ul>
       
   853 	 * <li></li>
       
   854 	 * </ul>
       
   855 	 * </p>
       
   856 	 * 
       
   857 	 * @param selectedCheckableFilename
       
   858 	 *            the file that has been unchecked by the user
       
   859 	 */
       
   860 	private void handleNoCheckRules(
       
   861 			CheckableResourceFilename uncheckedCheckableFilename) {
       
   862 		uncheckedCheckableFilename.setChecked(false);
       
   863 		resourceFilesViewer.setChecked(uncheckedCheckableFilename, false);
       
   864 	}
       
   865 
       
   866 	private void initialiseMaps() {
       
   867 		for (ResourcesEnums type : ResourcesEnums.values()) {
       
   868 			resourceFilesMap.put(type, null);
       
   869 		}
       
   870 	}
       
   871 
       
   872 	private void populateResourceFilesTable(String[] filenames,
       
   873 			ResourcesEnums resourceType) {
       
   874 		java.util.List<String> listOfFilenames = Helper
       
   875 				.toListOfStrings(filenames);
       
   876 		java.util.List<CheckableResourceFilename> checkableFilenames = new ArrayList<CheckableResourceFilename>();
       
   877 
       
   878 		for (String filename : listOfFilenames) {
       
   879 			CheckableResourceFilename crf = new CheckableResourceFilename(
       
   880 					filename);
       
   881 			checkableFilenames.add(crf);
       
   882 		}
       
   883 
       
   884 		IStructuredSelection ssel = (IStructuredSelection) resourceTypesViewer.getSelection();
       
   885 		if (!ssel.isEmpty()) {
       
   886 			ResourcesEnums selectedType = (ResourcesEnums) ssel.getFirstElement();
       
   887 			if (selectedType.equals(resourceType)) {
       
   888 				resourceFilesViewer.setInput(checkableFilenames);
       
   889 			}
       
   890 		}
       
   891 		resourceFilesMap.put(resourceType, checkableFilenames);
       
   892 	}
       
   893 
       
   894 	public void setBorderShapesFiles(String[] filenames) {
       
   895 		populateResourceFilesTable(filenames, ResourcesEnums.BORDER_SHAPES);
       
   896 	}
       
   897 
       
   898 	public void setBorderStylesFiles(String[] filenames) {
       
   899 		populateResourceFilesTable(filenames, ResourcesEnums.BORDER_STYLES);
       
   900 	}
       
   901 
       
   902 	public void setColoursFiles(String[] filenames) {
       
   903 		populateResourceFilesTable(filenames, ResourcesEnums.COLOURS);
       
   904 	}
       
   905 
       
   906 	public void setDependenciesFiles(String[] filenames) {
       
   907 		populateResourceFilesTable(filenames, ResourcesEnums.DEPENDENCIES);
       
   908 	}
       
   909 
       
   910 	public void setLevelsFiles(String[] filenames) {
       
   911 		populateResourceFilesTable(filenames, ResourcesEnums.LEVELS);
       
   912 	}
       
   913 
       
   914 	public void setLocalisationFiles(String[] filenames) {
       
   915 		populateResourceFilesTable(filenames, ResourcesEnums.LOCALISATION);
       
   916 	}
       
   917 
       
   918 	public void setPatternsFiles(String[] filenames) {
       
   919 		populateResourceFilesTable(filenames, ResourcesEnums.PATTERNS);
       
   920 	}
       
   921 
       
   922 	public void setS12XmlFiles(String[] filenames) {
       
   923 		populateResourceFilesTable(filenames, ResourcesEnums.S12_XML);
       
   924 	}
       
   925 
       
   926 	public void setSelectedBorderShapesFiles(String[] filenames) {
       
   927 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.BORDER_SHAPES);
       
   928 	}
       
   929 
       
   930 	public void setSelectedBorderStylesFiles(String[] filenames) {
       
   931 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.BORDER_STYLES);
       
   932 	}
       
   933 
       
   934 	public void setSelectedColoursFiles(String[] filenames) {
       
   935 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.COLOURS);
       
   936 	}
       
   937 
       
   938 	public void setSelectedDependenciesFiles(String[] filenames) {
       
   939 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.DEPENDENCIES);
       
   940 	}
       
   941 
       
   942 	public void setSelectedLevelsFiles(String[] filenames) {
       
   943 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.LEVELS);
       
   944 	}
       
   945 
       
   946 	public void setSelectedLocalisationFiles(String[] filenames) {
       
   947 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.LOCALISATION);
       
   948 	}
       
   949 
       
   950 	public void setSelectedPatternsFiles(String[] filenames) {
       
   951 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.PATTERNS);
       
   952 	}
       
   953 
       
   954 	public void setSelectedS12XmlFiles(String[] filenames) {
       
   955 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.S12_XML);
       
   956 	}
       
   957 
       
   958 	public void setSelectedShapesFiles(String[] filenames) {
       
   959 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.SHAPES);
       
   960 	}
       
   961 
       
   962 	public void setSelectedSystemInfoFiles(String[] filenames) {
       
   963 		checkFilesInResourceFilesTable(filenames, ResourcesEnums.SYSTEM_INFO);
       
   964 	}
       
   965 
       
   966 	public void setShapesFiles(String[] filenames) {
       
   967 		populateResourceFilesTable(filenames, ResourcesEnums.SHAPES);
       
   968 	}
       
   969 
       
   970 	public void setSystemInfoFiles(String[] filenames) {
       
   971 		populateResourceFilesTable(filenames, ResourcesEnums.SYSTEM_INFO);
       
   972 	}
       
   973 
       
   974 }