001: /*******************************************************************************
002: * Copyright (c) 2006, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.cheatsheet;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.core.runtime.jobs.ISchedulingRule;
014: import org.eclipse.jface.operation.IRunnableWithProgress;
015: import org.eclipse.pde.internal.core.cheatsheet.comp.CompCSWorkspaceModel;
016: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCS;
017: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSConstants;
018: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSIntro;
019: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSModelFactory;
020: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSObject;
021: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSOnCompletion;
022: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTask;
023: import org.eclipse.pde.internal.core.icheatsheet.comp.ICompCSTaskGroup;
024: import org.eclipse.pde.internal.ui.PDEUIMessages;
025:
026: /**
027: * CompCSCreationOperation
028: *
029: */
030: public class CompCSCreationOperation extends BaseCSCreationOperation
031: implements IRunnableWithProgress {
032:
033: /**
034: * @param file
035: */
036: public CompCSCreationOperation(IFile file) {
037: super (file);
038: }
039:
040: /**
041: * @param rule
042: */
043: public CompCSCreationOperation(ISchedulingRule rule) {
044: super (rule);
045: }
046:
047: /* (non-Javadoc)
048: * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.BaseCheatSheetCreationOperation#createContent()
049: */
050: protected void createContent() {
051: CompCSWorkspaceModel model = new CompCSWorkspaceModel(fFile,
052: false);
053: initializeCS(model.getCompCS());
054: model.save();
055: model.dispose();
056: }
057:
058: /**
059: * @param compCS
060: */
061: private void initializeCS(ICompCS compCS) {
062: // Create Task Group
063: // Element: taskGroup
064: ICompCSTaskGroup taskGroup = createBasicGroup(compCS);
065: // Create Task
066: // Element: task
067: ICompCSTask task = createBasicTask(taskGroup);
068: // Configure Group
069: taskGroup.addFieldTaskObject(task);
070: // Configure Cheat Sheet
071: // Attribute: name
072: compCS
073: .setFieldName(PDEUIMessages.CompCSCreationOperation_title);
074: compCS.setFieldTaskObject(taskGroup);
075: }
076:
077: /**
078: * @param parent
079: * @return
080: */
081: public static ICompCSTask createBasicTask(ICompCSObject parent) {
082: ICompCSModelFactory factory = parent.getModel().getFactory();
083: // Create Task
084: // Element: task
085: ICompCSTask task = factory.createCompCSTask(parent);
086: // Configure Task
087: // Element: intro
088: ICompCSIntro taskIntro = factory.createCompCSIntro(task);
089: taskIntro
090: .setFieldContent(formatTextBold(PDEUIMessages.CompCSCreationOperation_introduction));
091: // Element: onCompletion
092: ICompCSOnCompletion taskConclusion = factory
093: .createCompCSOnCompletion(task);
094: taskConclusion
095: .setFieldContent(formatTextBold(PDEUIMessages.CompCSCreationOperation_conclusion));
096: // Attribute: name
097: task.setFieldName(PDEUIMessages.CompCSCreationOperation_task);
098: // Attribute: kind
099: 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
115: .createCompCSTaskGroup(parent);
116: // Configure Task Group
117: // Element: intro
118: ICompCSIntro taskGroupIntro = factory
119: .createCompCSIntro(taskGroup);
120: taskGroupIntro
121: .setFieldContent(formatTextBold(PDEUIMessages.CompCSCreationOperation_introduction));
122: // Element: onCompletion
123: ICompCSOnCompletion taskGroupConclusion = factory
124: .createCompCSOnCompletion(taskGroup);
125: taskGroupConclusion
126: .setFieldContent(formatTextBold(PDEUIMessages.CompCSCreationOperation_conclusion));
127: // Attribute: name
128: taskGroup
129: .setFieldName(PDEUIMessages.CompCSCreationOperation_group);
130: // Attribute: kind
131: taskGroup.setFieldKind(ICompCSConstants.ATTRIBUTE_VALUE_SET);
132: taskGroup.setFieldIntro(taskGroupIntro);
133: taskGroup.setFieldOnCompletion(taskGroupConclusion);
134:
135: return taskGroup;
136: }
137: }
|