alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*******************************************************************************
 * Copyright (c) 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package model;

import org.eclipse.ui.examples.rcp.adventure.Activity;
import org.eclipse.ui.examples.rcp.adventure.Adventure;
import org.eclipse.ui.examples.rcp.adventure.AdventureFactory;
import org.eclipse.ui.examples.rcp.adventure.Catalog;
import org.eclipse.ui.examples.rcp.adventure.Category;

public class DummyCatalogService implements ICatalogService {
	private Catalog catalog;

	public Catalog getCatalog() {
		if (catalog == null) {
			createDummyCatalog();
		}
		return catalog;
	}

	private void createDummyCatalog() {
		catalog = AdventureFactory.eINSTANCE.createCatalog();
		catalog.setSource("Dummy Data");
		String locLogan = "Mount Logan";
		String locRockies = "Rocky Mountains";
		String locHornLake = "Horn Lake";
		String locAmazon = "Amazon Jungle";
		Category catMountain = category(catalog, "Mountain Adventures");
		Category catCave = category(catalog, "Cave Adventures");
		Category catJungle = category(catalog, "Jungle Adventures");
		Activity loganClimbing = activity(catalog, "Rock Climbing", locLogan, 100.00d);
		Activity rockiesBiking = activity(catalog, "Mountain Biking", locRockies, 125.00d);
		Activity rockiesSwimming = activity(catalog, "Swimming in Lake Louise", locRockies, 150.00d);
		Activity hornLakeRappel = activity(catalog, "Extreme Rappel", locHornLake, 175.00d);
		Activity amazonBoatRide = activity(catalog, "Boat Ride", locAmazon, 200.00d); 
		Activity amazonHiking = activity(catalog, "Hiking", locAmazon, 350.00d); 
		Activity amazonBirdWatching = activity(catalog, "Bird Watching", locAmazon, 199.00d); 
		Activity amazonRafting = activity(catalog, "Rafting", locAmazon, 145.00d); 
		Activity amazonCrocWrestling = activity(catalog, "Crocodile Wrestling", locAmazon, 189.00d); 
		adventure(catMountain, "Mount Logan Experience", locLogan, new Activity[] { loganClimbing });
		adventure(catMountain, "Rocky Mountains Experience", locRockies, new Activity[] { rockiesSwimming });
		adventure(catCave, "Horn Lake Experience", locHornLake, new Activity[] { hornLakeRappel });
		adventure(catJungle, "Amazon Appreciation Adventure", locAmazon, new Activity[] { amazonBoatRide, amazonHiking, amazonBirdWatching });
		adventure(catJungle, "Amazon Survival Adventure", locAmazon, new Activity[] { amazonHiking, amazonRafting, amazonCrocWrestling });
	}
	
	private Category category(Catalog catalog, String name) {
		Category category = AdventureFactory.eINSTANCE.createCategory();
		category.setName(name);
		catalog.getCategories().add(category);
		return category;
	}

	private Activity activity(Catalog catalog, String name, String location, double price) {
		Activity activity = AdventureFactory.eINSTANCE.createActivity();
		activity.setName(name);
		activity.setDescription("Some activity description");
		activity.setLocation(location);
		activity.setPrice(price);
		catalog.getActivities().add(activity);
		return activity;
	}
	
	private Adventure adventure(Category category, String name, String location, Activity[] activities) {
		Adventure adventure = AdventureFactory.eINSTANCE.createAdventure();
		adventure.setName(name);
		adventure.setDescription("Some adventure description");
		adventure.setLocation(location);
		category.getAdventures().add(adventure);
		for (int i = 0; i < activities.length; i++) {
			adventure.getDefaultActivities().add(activities[i]);
		}
		return adventure;
	}

}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.