KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > cheatsheet > CompCSCreationOperation


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.wizards.cheatsheet;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.jobs.ISchedulingRule;
16 import org.eclipse.jface.operation.IRunnableWithProgress;
17 import org.eclipse.pde.internal.core.cheatsheet.comp.CompCSWorkspaceModel;
18 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS;
19 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
20 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro;
21 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory;
22 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
23 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion;
24 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask;
25 import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27
28 /**
29  * CompCSCreationOperation
30  *
31  */

32 public class CompCSCreationOperation extends BaseCSCreationOperation
33         implements IRunnableWithProgress {
34
35     /**
36      * @param file
37      */

38     public CompCSCreationOperation(IFile file) {
39         super(file);
40     }
41
42     /**
43      * @param rule
44      */

45     public CompCSCreationOperation(ISchedulingRule rule) {
46         super(rule);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.BaseCheatSheetCreationOperation#createContent()
51      */

52     protected void createContent() {
53         CompCSWorkspaceModel model = new CompCSWorkspaceModel(fFile, false);
54         initializeCS(model.getCompCS());
55         model.save();
56         model.dispose();
57     }
58
59     /**
60      * @param compCS
61      */

62     private void initializeCS(ICompCS compCS) {
63         // Create Task Group
64
// Element: taskGroup
65
ICompCSTaskGroup taskGroup = createBasicGroup(compCS);
66         // Create Task
67
// Element: task
68
ICompCSTask task = createBasicTask(taskGroup);
69         // Configure Group
70
taskGroup.addFieldTaskObject(task);
71         // Configure Cheat Sheet
72
// Attribute: name
73
compCS.setFieldName(PDEUIMessages.CompCSCreationOperation_title);
74         compCS.setFieldTaskObject(taskGroup);
75     }
76
77     /**
78      * @param parent
79      * @return
80      */

81     public static ICompCSTask createBasicTask(ICompCSObject parent) {
82         ICompCSModelFactory factory = parent.getModel().getFactory();
83         // Create Task
84
// Element: task
85
ICompCSTask task = factory.createCompCSTask(parent);
86         // Configure Task
87
// Element: intro
88
ICompCSIntro taskIntro = factory.createCompCSIntro(task);
89         taskIntro.setFieldContent(
90                 formatTextBold(PDEUIMessages.CompCSCreationOperation_introduction));
91         // Element: onCompletion
92
ICompCSOnCompletion taskConclusion =
93             factory.createCompCSOnCompletion(task);
94         taskConclusion.setFieldContent(
95                 formatTextBold(PDEUIMessages.CompCSCreationOperation_conclusion));
96         // Attribute: name
97
task.setFieldName(PDEUIMessages.CompCSCreationOperation_task);
98         // Attribute: kind
99
task.setFieldKind(ICompCSConstants.ATTRIBUTE_VALUE_CHEATSHEET);
100         task.setFieldIntro(taskIntro);
101         task.setFieldOnCompletion(taskConclusion);
102         
103         return task;
104     }
105     
106     /**
107      * @param parent
108      * @return
109      */

110     public static ICompCSTaskGroup createBasicGroup(ICompCSObject parent) {
111         ICompCSModelFactory factory = parent.getModel().getFactory();
112         // Create Task Group
113
// Element: taskGroup
114
ICompCSTaskGroup taskGroup = factory.createCompCSTaskGroup(parent);
115         // Configure Task Group
116
// Element: intro
117
ICompCSIntro taskGroupIntro = factory.createCompCSIntro(taskGroup);
118         taskGroupIntro.setFieldContent(
119                 formatTextBold(PDEUIMessages.CompCSCreationOperation_introduction));
120         // Element: onCompletion
121
ICompCSOnCompletion taskGroupConclusion =
122             factory.createCompCSOnCompletion(taskGroup);
123         taskGroupConclusion.setFieldContent(
124                 formatTextBold(PDEUIMessages.CompCSCreationOperation_conclusion));
125         // Attribute: name
126
taskGroup.setFieldName(PDEUIMessages.CompCSCreationOperation_group);
127         // Attribute: kind
128
taskGroup.setFieldKind(ICompCSConstants.ATTRIBUTE_VALUE_SET);
129         taskGroup.setFieldIntro(taskGroupIntro);
130         taskGroup.setFieldOnCompletion(taskGroupConclusion);
131         
132         return taskGroup;
133     }
134 }
135
Popular Tags