| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.library.layout; |
| |
| import java.io.File; |
| |
| import org.eclipse.epf.library.configuration.ConfigurationHelper; |
| import org.eclipse.epf.library.edit.TngAdapterFactory; |
| import org.eclipse.epf.library.edit.util.ConfigurableComposedAdapterFactory; |
| import org.eclipse.epf.library.layout.diagram.IActivityDiagramService; |
| import org.eclipse.epf.library.layout.elements.AbstractElementLayout; |
| import org.eclipse.epf.library.layout.elements.GeneralLayout; |
| import org.eclipse.epf.library.services.LibraryProcessor; |
| import org.eclipse.epf.library.util.ResourceHelper; |
| |
| import com.ibm.uma.Activity; |
| import com.ibm.uma.MethodConfiguration; |
| import com.ibm.uma.MethodElement; |
| import com.ibm.uma.TaskDescriptor; |
| import com.ibm.uma.WorkBreakdownElement; |
| |
| /** |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class ElementLayoutManager { |
| |
| private static final String PACKAGE_NAME = ElementLayoutManager.class |
| .getPackage().getName(); |
| |
| private static final String default_config_path = "noconfig"; //$NON-NLS-1$ |
| |
| private String publish_dir = null; |
| |
| private MethodConfiguration config = null; |
| |
| private IActivityDiagramService diagramService = null; |
| |
| ConfigurableComposedAdapterFactory wbsAdapterFactory = null; |
| |
| ConfigurableComposedAdapterFactory tbsAdapterFactory = null; |
| |
| ConfigurableComposedAdapterFactory wpbsAdapterFactory = null; |
| |
| ConfigurableComposedAdapterFactory cbsAdapterFactory = null; |
| |
| public ElementLayoutManager() { |
| this(null, null); |
| } |
| |
| public ElementLayoutManager(MethodConfiguration config) { |
| this(config, null); |
| } |
| |
| public ElementLayoutManager(MethodConfiguration config, String publishdir) { |
| if (config != null) { |
| this.config = config; |
| } |
| |
| if (publishdir == null) { |
| publishdir = LayoutResources.getDefaultPublishDir(); |
| if (!publishdir.endsWith(File.separator)) { |
| publishdir += File.separator; |
| } |
| |
| // also append the configuration path |
| if (this.config == null) { |
| publishdir += default_config_path; |
| } else { |
| publishdir += this.config.getName(); |
| } |
| } |
| |
| setPublishDir(publishdir); |
| |
| // create adapt factories |
| wbsAdapterFactory = (ConfigurableComposedAdapterFactory) TngAdapterFactory.INSTANCE |
| .createWBSComposedAdapterFactory(); |
| tbsAdapterFactory = (ConfigurableComposedAdapterFactory) TngAdapterFactory.INSTANCE |
| .createTBSComposedAdapterFactory(); |
| wpbsAdapterFactory = (ConfigurableComposedAdapterFactory) TngAdapterFactory.INSTANCE |
| .createWPBSComposedAdapterFactory(); |
| cbsAdapterFactory = (ConfigurableComposedAdapterFactory) TngAdapterFactory.INSTANCE |
| .createProcessComposedAdapterFactory(); |
| |
| // set configuration filter |
| ProcessAdapterFactoryFilter configurator = new ProcessAdapterFactoryFilter( |
| this); |
| |
| wbsAdapterFactory.setFilter(configurator); |
| tbsAdapterFactory.setFilter(configurator); |
| wpbsAdapterFactory.setFilter(configurator); |
| cbsAdapterFactory.setFilter(configurator); |
| } |
| |
| public ConfigurableComposedAdapterFactory getWBSAdapterFactory() { |
| return wbsAdapterFactory; |
| } |
| |
| public ConfigurableComposedAdapterFactory getTBSAdapterFactory() { |
| return tbsAdapterFactory; |
| } |
| |
| public ConfigurableComposedAdapterFactory getWPBSAdapterFactory() { |
| return wpbsAdapterFactory; |
| } |
| |
| public ConfigurableComposedAdapterFactory getCBSAdapterFactory() { |
| return cbsAdapterFactory; |
| } |
| |
| public void setActivityDiagramService(IActivityDiagramService diagramService) { |
| this.diagramService = diagramService; |
| } |
| |
| public IActivityDiagramService getActivityDiagramService() { |
| return this.diagramService; |
| } |
| |
| private IElementLayout createLayout(MethodElement element) { |
| AbstractElementLayout layout = null; |
| |
| String className; |
| if (ConfigurationHelper.isDescriptionElement(element)) { |
| className = "ContentDescription"; //$NON-NLS-1$ |
| } else if (element instanceof Activity) { |
| className = "Activity"; //$NON-NLS-1$ |
| } else if ((element instanceof WorkBreakdownElement) |
| && !(element instanceof TaskDescriptor)) { |
| className = "WorkBreakdownElement"; //$NON-NLS-1$ // taskdescriptor has it's own layout |
| } else { |
| Class i[] = element.getClass().getInterfaces(); |
| if (i != null && i.length == 1) { |
| className = i[0].getName(); |
| } else { |
| className = element.getClass().getName(); |
| } |
| |
| int index = className.lastIndexOf("."); //$NON-NLS-1$ |
| if (index >= 0) { |
| className = className.substring(index + 1); |
| } |
| } |
| |
| className = PACKAGE_NAME + ".elements." + className + "Layout"; //$NON-NLS-1$ //$NON-NLS-2$ |
| |
| try { |
| Class c = Class.forName(className); |
| if (c != null) { |
| layout = (AbstractElementLayout) c.newInstance(); |
| } |
| } catch (Exception ex) { |
| // ex.printStackTrace(); |
| } |
| |
| if (layout == null) { |
| // System.out.println("Layout class '" + className + "' for element |
| // '" + element.getName() + "' not defined. Use GeneralLayout"); |
| layout = new GeneralLayout(); |
| } |
| |
| layout.init(this, element); |
| |
| return layout; |
| } |
| |
| public IElementLayout getLayout(MethodElement element, boolean create) { |
| // String id = element.getGuid(); |
| IElementLayout layout = null; // (IElementLayout)layoutMap.get(id); |
| if ((layout == null) && create) { |
| layout = createLayout(element); |
| // layoutMap.put(id, layout); |
| } |
| |
| return layout; |
| } |
| |
| public IElementLayout getLayout(String url) { |
| |
| // MethodElement element = (MethodElement)urlMap.get(url); |
| MethodElement element = ResourceHelper.getElementFromFileName(url); |
| if (element != null) { |
| return getLayout(element, true); |
| } else { |
| System.out.println("Can't find element for url '" + url + "'"); //$NON-NLS-1$ //$NON-NLS-2$ |
| } |
| |
| return null; |
| |
| } |
| |
| public MethodConfiguration getConfiguration() { |
| return this.config; |
| } |
| |
| public void setPublishDir(String path) { |
| this.publish_dir = path + File.separator; |
| |
| // initialize publishing site if needed |
| init_publishingSite(); |
| |
| } |
| |
| public String getPublishDir() { |
| return this.publish_dir; |
| } |
| |
| private void init_publishingSite() { |
| /* System.out |
| .println("Begin initializing publishing site: " + publish_dir); //$NON-NLS-1$ |
| */ |
| // copy the layout files from plugin layout to publishign site |
| LayoutResources.copyLayoutFiles(publish_dir); |
| |
| /* System.out.println("End initializing publishing site: " + publish_dir); //$NON-NLS-1$ |
| */ } |
| |
| public void copyLibraryResources() { |
| /* System.out |
| .println("Begin copying library resources to publishing site: " + publish_dir); //$NON-NLS-1$ |
| */ |
| // copy library resources from library to publishing site |
| File libRoot = LibraryProcessor.getInstance().getLibraryRootPath(); |
| if (libRoot != null) { |
| LayoutResources.copyDir(libRoot.getPath(), publish_dir); |
| } |
| |
| /* System.out |
| .println("End copying library resources to publishing site: " + publish_dir); //$NON-NLS-1$ |
| */ |
| } |
| |
| public void clear() { |
| // layoutMap.clear(); |
| |
| if (wbsAdapterFactory != null) { |
| wbsAdapterFactory.dispose(); |
| wbsAdapterFactory = null; |
| } |
| |
| if (tbsAdapterFactory != null) { |
| tbsAdapterFactory.dispose(); |
| tbsAdapterFactory = null; |
| } |
| |
| if (wpbsAdapterFactory != null) { |
| wpbsAdapterFactory.dispose(); |
| wpbsAdapterFactory = null; |
| } |
| |
| if (cbsAdapterFactory != null) { |
| cbsAdapterFactory.dispose(); |
| cbsAdapterFactory = null; |
| } |
| } |
| |
| } |