From 4ed8bddc791fda93940f238c5135556a07041dc0 Mon Sep 17 00:00:00 2001 From: rbrooks Date: Sat, 24 Jul 2010 08:02:08 +0000 Subject: converted all line terminators to unix style --- .../dsl/ui/integration/internal/Activator.java | 74 +-- .../operations/CreateEditorReportOperation.java | 208 +++--- .../ui/integration/operations/ExcelToEMFModel.java | 718 ++++++++++----------- .../operations/OseeTypesExportOperation.java | 132 ++-- .../operations/OseeTypesImportOperation.java | 282 ++++---- .../operations/ResolveImportsOperation.java | 198 +++--- .../operations/XtextOseeTypesHandler.java | 90 +-- .../dsl/ui/integration/wizards/LinkMessage.java | 58 +- .../core/dsl/ui/integration/wizards/LinkNode.java | 118 ++-- .../wizards/LinkNodeContentProvider.java | 120 ++-- .../integration/wizards/LinkNodeLabelProvider.java | 106 +-- .../integration/wizards/OseeTypesExportWizard.java | 118 ++-- .../integration/wizards/OseeTypesImportPage.java | 522 +++++++-------- .../integration/wizards/OseeTypesImportWizard.java | 142 ++-- .../integration/wizards/OseeTypesViewerFilter.java | 146 ++--- .../integration/wizards/ResourceSelectionPage.java | 176 ++--- .../integration/wizards/SelectOseeTypesPanel.java | 182 +++--- 17 files changed, 1695 insertions(+), 1695 deletions(-) (limited to 'plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src') diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/Activator.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/Activator.java index ce78f06f7a4..197161e4490 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/Activator.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/internal/Activator.java @@ -1,37 +1,37 @@ -package org.eclipse.osee.framework.core.dsl.ui.integration.internal; - -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.util.tracker.ServiceTracker; - -public class Activator implements BundleActivator { - public static final String PLUGIN_ID = "org.eclipse.osee.framework.core.dsl.ui.integration"; - private static BundleContext context; - private static Activator instance; - private ServiceTracker cacheServiceTracker; - - static BundleContext getContext() { - return context; - } - - @Override - public void start(BundleContext bundleContext) throws Exception { - Activator.instance = this; - Activator.context = bundleContext; - cacheServiceTracker = new ServiceTracker(context, IOseeCachingService.class.getName(), null); - cacheServiceTracker.open(true); - } - - @Override - public void stop(BundleContext bundleContext) throws Exception { - Activator.context = null; - if (cacheServiceTracker != null) { - cacheServiceTracker.close(); - } - } - - public static IOseeCachingService getOseeCacheService() { - return (IOseeCachingService) Activator.instance.cacheServiceTracker.getService(); - } -} +package org.eclipse.osee.framework.core.dsl.ui.integration.internal; + +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.util.tracker.ServiceTracker; + +public class Activator implements BundleActivator { + public static final String PLUGIN_ID = "org.eclipse.osee.framework.core.dsl.ui.integration"; + private static BundleContext context; + private static Activator instance; + private ServiceTracker cacheServiceTracker; + + static BundleContext getContext() { + return context; + } + + @Override + public void start(BundleContext bundleContext) throws Exception { + Activator.instance = this; + Activator.context = bundleContext; + cacheServiceTracker = new ServiceTracker(context, IOseeCachingService.class.getName(), null); + cacheServiceTracker.open(true); + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + if (cacheServiceTracker != null) { + cacheServiceTracker.close(); + } + } + + public static IOseeCachingService getOseeCacheService() { + return (IOseeCachingService) Activator.instance.cacheServiceTracker.getService(); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/CreateEditorReportOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/CreateEditorReportOperation.java index 30dc98e1828..d501a0716d4 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/CreateEditorReportOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/CreateEditorReportOperation.java @@ -1,104 +1,104 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.nebula.widgets.xviewer.XViewerColumn; -import org.eclipse.nebula.widgets.xviewer.XViewerColumn.SortDataType; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.message.TableData; -import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorProvider; -import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorTab; -import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor; -import org.eclipse.osee.framework.ui.skynet.results.table.IResultsXViewerRow; -import org.eclipse.osee.framework.ui.skynet.results.table.ResultsEditorTableTab; -import org.eclipse.osee.framework.ui.skynet.results.table.ResultsXViewerRow; -import org.eclipse.swt.SWT; -import org.eclipse.ui.progress.UIJob; - -/** - * @author Roberto E. Escobar - */ -public class CreateEditorReportOperation extends AbstractOperation { - private final Collection tableData; - private final String reportName; - - public CreateEditorReportOperation(String reportName, Collection tableData) { - super("Generate Report", Activator.PLUGIN_ID); - this.tableData = tableData; - this.reportName = reportName; - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - List tabs = new ArrayList(); - for (TableData data : tableData) { - List columns = new ArrayList(); - for (String name : data.getColumns()) { - columns.add(new XViewerColumn(name, name, 80, SWT.LEFT, true, SortDataType.String, false, "")); - } - List rows = new ArrayList(); - for (String[] row : data.getRows()) { - rows.add(new ResultsXViewerRow(row)); - } - tabs.add(new ResultsEditorTableTab(data.getTitle(), columns, rows)); - } - openReport(tabs); - } - - private void openReport(final List resultsTabs) { - Job job = new UIJob(reportName) { - - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - IStatus status; - try { - ResultsEditor.open(new ReportProvider(getName(), resultsTabs)); - status = Status.OK_STATUS; - } catch (Exception ex) { - status = - new Status(IStatus.ERROR, Activator.PLUGIN_ID, String.format("Error creating %s Report", - reportName), ex); - } - return status; - } - }; - Operations.scheduleJob(job, true, Job.SHORT, null); - } - - private static final class ReportProvider implements IResultsEditorProvider { - private final List resultsTabs; - private final String editorName; - - public ReportProvider(String editorName, List resultsTabs) { - this.resultsTabs = resultsTabs; - this.editorName = editorName; - } - - @Override - public String getEditorName() { - return editorName; - } - - @Override - public List getResultsEditorTabs() { - return resultsTabs; - } - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.nebula.widgets.xviewer.XViewerColumn; +import org.eclipse.nebula.widgets.xviewer.XViewerColumn.SortDataType; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.message.TableData; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorProvider; +import org.eclipse.osee.framework.ui.skynet.results.IResultsEditorTab; +import org.eclipse.osee.framework.ui.skynet.results.ResultsEditor; +import org.eclipse.osee.framework.ui.skynet.results.table.IResultsXViewerRow; +import org.eclipse.osee.framework.ui.skynet.results.table.ResultsEditorTableTab; +import org.eclipse.osee.framework.ui.skynet.results.table.ResultsXViewerRow; +import org.eclipse.swt.SWT; +import org.eclipse.ui.progress.UIJob; + +/** + * @author Roberto E. Escobar + */ +public class CreateEditorReportOperation extends AbstractOperation { + private final Collection tableData; + private final String reportName; + + public CreateEditorReportOperation(String reportName, Collection tableData) { + super("Generate Report", Activator.PLUGIN_ID); + this.tableData = tableData; + this.reportName = reportName; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + List tabs = new ArrayList(); + for (TableData data : tableData) { + List columns = new ArrayList(); + for (String name : data.getColumns()) { + columns.add(new XViewerColumn(name, name, 80, SWT.LEFT, true, SortDataType.String, false, "")); + } + List rows = new ArrayList(); + for (String[] row : data.getRows()) { + rows.add(new ResultsXViewerRow(row)); + } + tabs.add(new ResultsEditorTableTab(data.getTitle(), columns, rows)); + } + openReport(tabs); + } + + private void openReport(final List resultsTabs) { + Job job = new UIJob(reportName) { + + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + IStatus status; + try { + ResultsEditor.open(new ReportProvider(getName(), resultsTabs)); + status = Status.OK_STATUS; + } catch (Exception ex) { + status = + new Status(IStatus.ERROR, Activator.PLUGIN_ID, String.format("Error creating %s Report", + reportName), ex); + } + return status; + } + }; + Operations.scheduleJob(job, true, Job.SHORT, null); + } + + private static final class ReportProvider implements IResultsEditorProvider { + private final List resultsTabs; + private final String editorName; + + public ReportProvider(String editorName, List resultsTabs) { + this.resultsTabs = resultsTabs; + this.editorName = editorName; + } + + @Override + public String getEditorName() { + return editorName; + } + + @Override + public List getResultsEditorTabs() { + return resultsTabs; + } + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ExcelToEMFModel.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ExcelToEMFModel.java index eab01aec740..d053b21b9f9 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ExcelToEMFModel.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ExcelToEMFModel.java @@ -1,359 +1,359 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.eclipse.emf.common.util.EList; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; -import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationMultiplicityEnum; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeTypeRef; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumEntry; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumType; -import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; -import org.eclipse.osee.framework.core.exception.OseeArgumentException; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.OseeExceptions; -import org.eclipse.osee.framework.core.exception.OseeInvalidInheritanceException; -import org.eclipse.osee.framework.core.exception.OseeStateException; -import org.eclipse.osee.framework.jdk.core.type.Pair; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; -import org.eclipse.osee.framework.skynet.core.artifact.Attribute; -import org.eclipse.osee.framework.skynet.core.attribute.AttributeExtensionManager; -import org.eclipse.osee.framework.skynet.core.attribute.EnumeratedAttribute; -import org.eclipse.osee.framework.skynet.core.importing.IOseeDataTypeProcessor; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * @author Roberto E. Escobar - */ -public class ExcelToEMFModel implements IOseeDataTypeProcessor { - private final OseeDslFactory factory; - private final Map oseeModels; - private OseeDsl currentModel; - - public ExcelToEMFModel(Map oseeModels) { - this.factory = OseeDslFactory.eINSTANCE; - this.oseeModels = oseeModels; - } - - public void createModel(String name) { - currentModel = factory.createOseeDsl(); - oseeModels.put(name, currentModel); - } - - private OseeDsl getCurrentModel() { - return currentModel; - } - - private String toQualifiedName(String name) { - return "\"" + name + "\""; - } - - private OseeType getObject(String name, Class classToLookFor) throws OseeArgumentException { - EList types; - - if (classToLookFor.equals(XArtifactType.class)) { - types = getCurrentModel().getArtifactTypes(); - } else if (classToLookFor.equals(XAttributeType.class)) { - types = getCurrentModel().getAttributeTypes(); - } else if (classToLookFor.equals(XRelationType.class)) { - types = getCurrentModel().getRelationTypes(); - } else if (classToLookFor.equals(XOseeEnumType.class)) { - types = getCurrentModel().getEnumTypes(); - } else { - throw new OseeArgumentException(classToLookFor.getName() + " not a supported type"); - } - for (OseeType oseeTypes : types) { - if (name.equals(oseeTypes.getName())) { - return classToLookFor.cast(oseeTypes); - } - } - return null; - } - - @Override - public void onArtifactTypeInheritance(String ancestor, Collection descendants) throws OseeCoreException { - XArtifactType ancestorType = (XArtifactType) getObject(ancestor, XArtifactType.class); - if (ancestorType == null) { - throw new OseeInvalidInheritanceException("Ancestor [%s]"); - } - - // if (superArtifactTypeName != null) { - // ArtifactType superArtifactType = (ArtifactType) getObject(superArtifactTypeName, ArtifactType.class); - // if (superArtifactType == null) { - // boolean isAbstractSuper = false; - // onArtifactType(isAbstractSuper, superArtifactTypeName, null); - // superArtifactType = (ArtifactType) getObject(superArtifactTypeName, ArtifactType.class); - // } - // artifactType.setSuperArtifactType(superArtifactType); - // } - } - - @Override - public void onArtifactType(boolean isAbstract, String name) throws OseeCoreException { - String id = toQualifiedName(name); - OseeType types = getObject(id, XArtifactType.class); - if (types == null) { - XArtifactType artifactType = factory.createXArtifactType(); - artifactType.setName(id); - getCurrentModel().getArtifactTypes().add(artifactType); - } - } - - @Override - public void onAttributeType(String attributeBaseType, String attributeProviderTypeName, String fileTypeExtension, String name, String defaultValue, String validityXml, int minOccurrence, int maxOccurrence, String toolTipText, String taggerId) throws OseeCoreException { - String id = toQualifiedName(name); - OseeType types = getObject(id, XAttributeType.class); - if (types == null) { - XAttributeType attributeType = factory.createXAttributeType(); - attributeType.setName(id); - attributeType.setBaseAttributeType(Lib.getExtension(attributeBaseType)); - attributeType.setDataProvider(Lib.getExtension(attributeProviderTypeName)); - attributeType.setMin(String.valueOf(minOccurrence)); - - String maxValue; - if (maxOccurrence == Integer.MAX_VALUE) { - maxValue = "unlimited"; - } else { - maxValue = String.valueOf(maxOccurrence); - } - attributeType.setMax(maxValue); - - if (Strings.isValid(fileTypeExtension)) { - attributeType.setFileExtension(fileTypeExtension); - } - if (Strings.isValid(defaultValue)) { - attributeType.setDefaultValue(defaultValue); - } - if (Strings.isValid(toolTipText)) { - attributeType.setDescription(toolTipText); - } - if (Strings.isValid(taggerId)) { - attributeType.setTaggerId(taggerId); - } - - XOseeEnumType enumType = getEnumType(attributeBaseType, attributeProviderTypeName, name, validityXml); - if (enumType != null) { - attributeType.setEnumType(enumType); - } - getCurrentModel().getAttributeTypes().add(attributeType); - } - } - - @Override - public boolean doesArtifactSuperTypeExist(String artifactSuperTypeName) throws OseeCoreException { - return getObject(artifactSuperTypeName, XArtifactType.class) != null; - } - - @Override - public void onAttributeValidity(String attributeName, String artifactSuperTypeName, Collection concreteTypes) throws OseeCoreException { - XArtifactType superArtifactType = - (XArtifactType) getObject(toQualifiedName(artifactSuperTypeName), XArtifactType.class); - XAttributeType attributeType = (XAttributeType) getObject(toQualifiedName(attributeName), XAttributeType.class); - - if (superArtifactType == null && "Artifact".equals(artifactSuperTypeName)) { - onArtifactType(false, "Artifact"); - superArtifactType = (XArtifactType) getObject(toQualifiedName(artifactSuperTypeName), XArtifactType.class); - } - - if (superArtifactType == null || attributeType == null) { - throw new OseeStateException(String.format("Type Missing: %s - %s", artifactSuperTypeName, attributeName)); - } - XAttributeTypeRef reference = factory.createXAttributeTypeRef(); - reference.setValidAttributeType(attributeType); - superArtifactType.getValidAttributeTypes().add(reference); - } - - @Override - public void onRelationType(String name, String sideAName, String sideBName, String artifactTypeSideA, String artifactTypeSideB, String multiplicity, String ordered, String defaultOrderTypeGuid) throws OseeCoreException { - String id = toQualifiedName(name); - OseeType types = getObject(id, XRelationType.class); - if (types == null) { - XRelationType relationType = factory.createXRelationType(); - relationType.setName(id); - relationType.setSideAName(sideAName); - relationType.setSideBName(sideBName); - - String arranger; - if ("Yes".equals(ordered)) { - arranger = "Lexicographical_Ascending"; - } else { - arranger = "Unordered"; - } - relationType.setDefaultOrderType(arranger); - getCurrentModel().getRelationTypes().add(relationType); - } - } - - @Override - public void onRelationValidity(String artifactTypeName, String relationTypeName, int sideAMax, int sideBMax) throws OseeCoreException { - XRelationType relationType = (XRelationType) getObject(toQualifiedName(relationTypeName), XRelationType.class); - XArtifactType artifactType = (XArtifactType) getObject(toQualifiedName(artifactTypeName), XArtifactType.class); - - if (sideAMax > 0) { - relationType.setSideAArtifactType(artifactType); - } - if (sideBMax > 0) { - relationType.setSideBArtifactType(artifactType); - } - - RelationMultiplicityEnum multiplicity = relationType.getMultiplicity(); - if (sideAMax == Integer.MAX_VALUE && sideBMax == 1) { - multiplicity = RelationMultiplicityEnum.ONE_TO_MANY; - - } else if (sideAMax == 1 && sideBMax == Integer.MAX_VALUE) { - multiplicity = RelationMultiplicityEnum.MANY_TO_ONE; - - } else if (sideAMax == Integer.MAX_VALUE && sideBMax == Integer.MAX_VALUE) { - multiplicity = RelationMultiplicityEnum.MANY_TO_MANY; - } else if (sideAMax == 1 && sideBMax == 1) { - multiplicity = RelationMultiplicityEnum.ONE_TO_ONE; - } else { - System.out.println("None detected - " + relationTypeName); - } - - if (multiplicity != null && !multiplicity.equals(relationType.getMultiplicity())) { - relationType.setMultiplicity(multiplicity); - } else { - System.out.println("Null multiplicity - " + relationTypeName); - } - } - - private static void checkEnumTypeName(String enumTypeName) throws OseeCoreException { - if (!Strings.isValid(enumTypeName)) { - throw new OseeArgumentException("Osee Enum Type Name cannot be null."); - } - } - - private XOseeEnumType getEnumType(String attributeBaseType, String attributeProviderTypeName, String name, String validityXml) throws OseeCoreException { - Class> baseAttributeClass = - AttributeExtensionManager.getAttributeClassFor(attributeBaseType); - - XOseeEnumType oseeEnumType = null; - if (EnumeratedAttribute.class.isAssignableFrom(baseAttributeClass)) { - createEnumTypeFromXml(toQualifiedEnumName(name), validityXml); - } - return oseeEnumType; - } - - private String toQualifiedEnumName(String name) { - return "\"" + name + ".enum\""; - } - - private XOseeEnumType createEnumTypeFromXml(String attributeTypeName, String xmlDefinition) throws OseeCoreException { - List> entries = new ArrayList>(); - String enumTypeName = ""; - - if (!Strings.isValid(xmlDefinition)) { - throw new OseeArgumentException("The enum xml definition must not be null or empty"); - } - - Document document = null; - try { - document = Jaxp.readXmlDocument(xmlDefinition); - } catch (Exception ex) { - OseeExceptions.wrapAndThrow(ex); - } - enumTypeName = attributeTypeName; - Element choicesElement = document.getDocumentElement(); - NodeList enumerations = choicesElement.getChildNodes(); - Set choices = new LinkedHashSet(); - - for (int i = 0; i < enumerations.getLength(); i++) { - Node node = enumerations.item(i); - if (node.getNodeName().equalsIgnoreCase("Enum")) { - choices.add(node.getTextContent()); - } else { - throw new OseeArgumentException("Validity Xml not of excepted enum format"); - } - } - - int ordinal = 0; - for (String choice : choices) { - entries.add(new Pair(choice, ordinal++)); - } - - return createEnumType(enumTypeName, entries); - } - - private XOseeEnumType createEnumType(String enumTypeName, List> entries) throws OseeCoreException { - checkEnumTypeName(enumTypeName); - checkEntryIntegrity(enumTypeName, entries); - - XOseeEnumType oseeEnumType = null; - - OseeType types = getObject(enumTypeName, XOseeEnumType.class); - if (types == null) { - oseeEnumType = factory.createXOseeEnumType(); - oseeEnumType.setName(enumTypeName); - - for (Pair entry : entries) { - XOseeEnumEntry oseeEnum = factory.createXOseeEnumEntry(); - oseeEnum.setName(entry.getFirst()); - oseeEnum.setOrdinal(String.valueOf(entry.getSecond())); - oseeEnumType.getEnumEntries().add(oseeEnum); - } - getCurrentModel().getEnumTypes().add(oseeEnumType); - } else { - oseeEnumType = (XOseeEnumType) types; - } - return oseeEnumType; - } - - private static void checkEntryIntegrity(String enumTypeName, List> entries) throws OseeCoreException { - if (entries == null) { - throw new OseeArgumentException(String.format("Osee Enum Type [%s] had null entries", enumTypeName)); - } - - // if (entries.size() <= 0) throw new OseeArgumentException(String.format("Osee Enum Type [%s] had 0 entries", - // enumTypeName)); - Map values = new HashMap(); - for (Pair entry : entries) { - String name = entry.getFirst(); - int ordinal = entry.getSecond(); - if (!Strings.isValid(name)) { - throw new OseeArgumentException("Enum entry name cannot be null"); - } - if (ordinal < 0) { - throw new OseeArgumentException("Enum entry ordinal cannot be of negative value"); - } - if (values.containsKey(name)) { - throw new OseeArgumentException(String.format("Unique enum entry name violation - [%s] already exists.", - name)); - } - if (values.containsValue(ordinal)) { - throw new OseeArgumentException(String.format("Unique enum entry ordinal violation - [%s] already exists.", - ordinal)); - } - values.put(name, ordinal); - } - } - - @Override - public void onFinish() { - - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.eclipse.emf.common.util.EList; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory; +import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationMultiplicityEnum; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeTypeRef; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumEntry; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XOseeEnumType; +import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType; +import org.eclipse.osee.framework.core.exception.OseeArgumentException; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.exception.OseeInvalidInheritanceException; +import org.eclipse.osee.framework.core.exception.OseeStateException; +import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; +import org.eclipse.osee.framework.skynet.core.artifact.Attribute; +import org.eclipse.osee.framework.skynet.core.attribute.AttributeExtensionManager; +import org.eclipse.osee.framework.skynet.core.attribute.EnumeratedAttribute; +import org.eclipse.osee.framework.skynet.core.importing.IOseeDataTypeProcessor; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * @author Roberto E. Escobar + */ +public class ExcelToEMFModel implements IOseeDataTypeProcessor { + private final OseeDslFactory factory; + private final Map oseeModels; + private OseeDsl currentModel; + + public ExcelToEMFModel(Map oseeModels) { + this.factory = OseeDslFactory.eINSTANCE; + this.oseeModels = oseeModels; + } + + public void createModel(String name) { + currentModel = factory.createOseeDsl(); + oseeModels.put(name, currentModel); + } + + private OseeDsl getCurrentModel() { + return currentModel; + } + + private String toQualifiedName(String name) { + return "\"" + name + "\""; + } + + private OseeType getObject(String name, Class classToLookFor) throws OseeArgumentException { + EList types; + + if (classToLookFor.equals(XArtifactType.class)) { + types = getCurrentModel().getArtifactTypes(); + } else if (classToLookFor.equals(XAttributeType.class)) { + types = getCurrentModel().getAttributeTypes(); + } else if (classToLookFor.equals(XRelationType.class)) { + types = getCurrentModel().getRelationTypes(); + } else if (classToLookFor.equals(XOseeEnumType.class)) { + types = getCurrentModel().getEnumTypes(); + } else { + throw new OseeArgumentException(classToLookFor.getName() + " not a supported type"); + } + for (OseeType oseeTypes : types) { + if (name.equals(oseeTypes.getName())) { + return classToLookFor.cast(oseeTypes); + } + } + return null; + } + + @Override + public void onArtifactTypeInheritance(String ancestor, Collection descendants) throws OseeCoreException { + XArtifactType ancestorType = (XArtifactType) getObject(ancestor, XArtifactType.class); + if (ancestorType == null) { + throw new OseeInvalidInheritanceException("Ancestor [%s]"); + } + + // if (superArtifactTypeName != null) { + // ArtifactType superArtifactType = (ArtifactType) getObject(superArtifactTypeName, ArtifactType.class); + // if (superArtifactType == null) { + // boolean isAbstractSuper = false; + // onArtifactType(isAbstractSuper, superArtifactTypeName, null); + // superArtifactType = (ArtifactType) getObject(superArtifactTypeName, ArtifactType.class); + // } + // artifactType.setSuperArtifactType(superArtifactType); + // } + } + + @Override + public void onArtifactType(boolean isAbstract, String name) throws OseeCoreException { + String id = toQualifiedName(name); + OseeType types = getObject(id, XArtifactType.class); + if (types == null) { + XArtifactType artifactType = factory.createXArtifactType(); + artifactType.setName(id); + getCurrentModel().getArtifactTypes().add(artifactType); + } + } + + @Override + public void onAttributeType(String attributeBaseType, String attributeProviderTypeName, String fileTypeExtension, String name, String defaultValue, String validityXml, int minOccurrence, int maxOccurrence, String toolTipText, String taggerId) throws OseeCoreException { + String id = toQualifiedName(name); + OseeType types = getObject(id, XAttributeType.class); + if (types == null) { + XAttributeType attributeType = factory.createXAttributeType(); + attributeType.setName(id); + attributeType.setBaseAttributeType(Lib.getExtension(attributeBaseType)); + attributeType.setDataProvider(Lib.getExtension(attributeProviderTypeName)); + attributeType.setMin(String.valueOf(minOccurrence)); + + String maxValue; + if (maxOccurrence == Integer.MAX_VALUE) { + maxValue = "unlimited"; + } else { + maxValue = String.valueOf(maxOccurrence); + } + attributeType.setMax(maxValue); + + if (Strings.isValid(fileTypeExtension)) { + attributeType.setFileExtension(fileTypeExtension); + } + if (Strings.isValid(defaultValue)) { + attributeType.setDefaultValue(defaultValue); + } + if (Strings.isValid(toolTipText)) { + attributeType.setDescription(toolTipText); + } + if (Strings.isValid(taggerId)) { + attributeType.setTaggerId(taggerId); + } + + XOseeEnumType enumType = getEnumType(attributeBaseType, attributeProviderTypeName, name, validityXml); + if (enumType != null) { + attributeType.setEnumType(enumType); + } + getCurrentModel().getAttributeTypes().add(attributeType); + } + } + + @Override + public boolean doesArtifactSuperTypeExist(String artifactSuperTypeName) throws OseeCoreException { + return getObject(artifactSuperTypeName, XArtifactType.class) != null; + } + + @Override + public void onAttributeValidity(String attributeName, String artifactSuperTypeName, Collection concreteTypes) throws OseeCoreException { + XArtifactType superArtifactType = + (XArtifactType) getObject(toQualifiedName(artifactSuperTypeName), XArtifactType.class); + XAttributeType attributeType = (XAttributeType) getObject(toQualifiedName(attributeName), XAttributeType.class); + + if (superArtifactType == null && "Artifact".equals(artifactSuperTypeName)) { + onArtifactType(false, "Artifact"); + superArtifactType = (XArtifactType) getObject(toQualifiedName(artifactSuperTypeName), XArtifactType.class); + } + + if (superArtifactType == null || attributeType == null) { + throw new OseeStateException(String.format("Type Missing: %s - %s", artifactSuperTypeName, attributeName)); + } + XAttributeTypeRef reference = factory.createXAttributeTypeRef(); + reference.setValidAttributeType(attributeType); + superArtifactType.getValidAttributeTypes().add(reference); + } + + @Override + public void onRelationType(String name, String sideAName, String sideBName, String artifactTypeSideA, String artifactTypeSideB, String multiplicity, String ordered, String defaultOrderTypeGuid) throws OseeCoreException { + String id = toQualifiedName(name); + OseeType types = getObject(id, XRelationType.class); + if (types == null) { + XRelationType relationType = factory.createXRelationType(); + relationType.setName(id); + relationType.setSideAName(sideAName); + relationType.setSideBName(sideBName); + + String arranger; + if ("Yes".equals(ordered)) { + arranger = "Lexicographical_Ascending"; + } else { + arranger = "Unordered"; + } + relationType.setDefaultOrderType(arranger); + getCurrentModel().getRelationTypes().add(relationType); + } + } + + @Override + public void onRelationValidity(String artifactTypeName, String relationTypeName, int sideAMax, int sideBMax) throws OseeCoreException { + XRelationType relationType = (XRelationType) getObject(toQualifiedName(relationTypeName), XRelationType.class); + XArtifactType artifactType = (XArtifactType) getObject(toQualifiedName(artifactTypeName), XArtifactType.class); + + if (sideAMax > 0) { + relationType.setSideAArtifactType(artifactType); + } + if (sideBMax > 0) { + relationType.setSideBArtifactType(artifactType); + } + + RelationMultiplicityEnum multiplicity = relationType.getMultiplicity(); + if (sideAMax == Integer.MAX_VALUE && sideBMax == 1) { + multiplicity = RelationMultiplicityEnum.ONE_TO_MANY; + + } else if (sideAMax == 1 && sideBMax == Integer.MAX_VALUE) { + multiplicity = RelationMultiplicityEnum.MANY_TO_ONE; + + } else if (sideAMax == Integer.MAX_VALUE && sideBMax == Integer.MAX_VALUE) { + multiplicity = RelationMultiplicityEnum.MANY_TO_MANY; + } else if (sideAMax == 1 && sideBMax == 1) { + multiplicity = RelationMultiplicityEnum.ONE_TO_ONE; + } else { + System.out.println("None detected - " + relationTypeName); + } + + if (multiplicity != null && !multiplicity.equals(relationType.getMultiplicity())) { + relationType.setMultiplicity(multiplicity); + } else { + System.out.println("Null multiplicity - " + relationTypeName); + } + } + + private static void checkEnumTypeName(String enumTypeName) throws OseeCoreException { + if (!Strings.isValid(enumTypeName)) { + throw new OseeArgumentException("Osee Enum Type Name cannot be null."); + } + } + + private XOseeEnumType getEnumType(String attributeBaseType, String attributeProviderTypeName, String name, String validityXml) throws OseeCoreException { + Class> baseAttributeClass = + AttributeExtensionManager.getAttributeClassFor(attributeBaseType); + + XOseeEnumType oseeEnumType = null; + if (EnumeratedAttribute.class.isAssignableFrom(baseAttributeClass)) { + createEnumTypeFromXml(toQualifiedEnumName(name), validityXml); + } + return oseeEnumType; + } + + private String toQualifiedEnumName(String name) { + return "\"" + name + ".enum\""; + } + + private XOseeEnumType createEnumTypeFromXml(String attributeTypeName, String xmlDefinition) throws OseeCoreException { + List> entries = new ArrayList>(); + String enumTypeName = ""; + + if (!Strings.isValid(xmlDefinition)) { + throw new OseeArgumentException("The enum xml definition must not be null or empty"); + } + + Document document = null; + try { + document = Jaxp.readXmlDocument(xmlDefinition); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + enumTypeName = attributeTypeName; + Element choicesElement = document.getDocumentElement(); + NodeList enumerations = choicesElement.getChildNodes(); + Set choices = new LinkedHashSet(); + + for (int i = 0; i < enumerations.getLength(); i++) { + Node node = enumerations.item(i); + if (node.getNodeName().equalsIgnoreCase("Enum")) { + choices.add(node.getTextContent()); + } else { + throw new OseeArgumentException("Validity Xml not of excepted enum format"); + } + } + + int ordinal = 0; + for (String choice : choices) { + entries.add(new Pair(choice, ordinal++)); + } + + return createEnumType(enumTypeName, entries); + } + + private XOseeEnumType createEnumType(String enumTypeName, List> entries) throws OseeCoreException { + checkEnumTypeName(enumTypeName); + checkEntryIntegrity(enumTypeName, entries); + + XOseeEnumType oseeEnumType = null; + + OseeType types = getObject(enumTypeName, XOseeEnumType.class); + if (types == null) { + oseeEnumType = factory.createXOseeEnumType(); + oseeEnumType.setName(enumTypeName); + + for (Pair entry : entries) { + XOseeEnumEntry oseeEnum = factory.createXOseeEnumEntry(); + oseeEnum.setName(entry.getFirst()); + oseeEnum.setOrdinal(String.valueOf(entry.getSecond())); + oseeEnumType.getEnumEntries().add(oseeEnum); + } + getCurrentModel().getEnumTypes().add(oseeEnumType); + } else { + oseeEnumType = (XOseeEnumType) types; + } + return oseeEnumType; + } + + private static void checkEntryIntegrity(String enumTypeName, List> entries) throws OseeCoreException { + if (entries == null) { + throw new OseeArgumentException(String.format("Osee Enum Type [%s] had null entries", enumTypeName)); + } + + // if (entries.size() <= 0) throw new OseeArgumentException(String.format("Osee Enum Type [%s] had 0 entries", + // enumTypeName)); + Map values = new HashMap(); + for (Pair entry : entries) { + String name = entry.getFirst(); + int ordinal = entry.getSecond(); + if (!Strings.isValid(name)) { + throw new OseeArgumentException("Enum entry name cannot be null"); + } + if (ordinal < 0) { + throw new OseeArgumentException("Enum entry ordinal cannot be of negative value"); + } + if (values.containsKey(name)) { + throw new OseeArgumentException(String.format("Unique enum entry name violation - [%s] already exists.", + name)); + } + if (values.containsValue(ordinal)) { + throw new OseeArgumentException(String.format("Unique enum entry ordinal violation - [%s] already exists.", + ordinal)); + } + values.put(name, ordinal); + } + } + + @Override + public void onFinish() { + + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesExportOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesExportOperation.java index acccd443f72..f2d269fa248 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesExportOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesExportOperation.java @@ -1,66 +1,66 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.client.ClientSessionManager; -import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient; -import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.core.util.HttpProcessor; -import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult; -import org.eclipse.osee.framework.jdk.core.util.Lib; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesExportOperation extends AbstractOperation { - private final File folder; - - public OseeTypesExportOperation(File folder) { - super("Export Osee Types Model", Activator.PLUGIN_ID); - this.folder = folder; - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - Map parameters = new HashMap(); - parameters.put("sessionId", ClientSessionManager.getSessionId()); - - String url = - HttpUrlBuilderClient.getInstance().getOsgiServletServiceUrl(OseeServerContext.OSEE_MODEL_CONTEXT, - parameters); - - OutputStream outputStream = null; - try { - outputStream = new BufferedOutputStream(new FileOutputStream(new File(folder, getOseeFileName()))); - AcquireResult results = HttpProcessor.acquire(new URL(url), outputStream); - if (!results.wasSuccessful()) { - throw new OseeCoreException("Error exporting osee types"); - } - } finally { - Lib.close(outputStream); - } - } - - private String getOseeFileName() { - return "OseeTypes_" + Lib.getDateTimeString() + ".osee"; - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.client.ClientSessionManager; +import org.eclipse.osee.framework.core.client.server.HttpUrlBuilderClient; +import org.eclipse.osee.framework.core.data.OseeServerContext; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.util.HttpProcessor; +import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult; +import org.eclipse.osee.framework.jdk.core.util.Lib; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesExportOperation extends AbstractOperation { + private final File folder; + + public OseeTypesExportOperation(File folder) { + super("Export Osee Types Model", Activator.PLUGIN_ID); + this.folder = folder; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + Map parameters = new HashMap(); + parameters.put("sessionId", ClientSessionManager.getSessionId()); + + String url = + HttpUrlBuilderClient.getInstance().getOsgiServletServiceUrl(OseeServerContext.OSEE_MODEL_CONTEXT, + parameters); + + OutputStream outputStream = null; + try { + outputStream = new BufferedOutputStream(new FileOutputStream(new File(folder, getOseeFileName()))); + AcquireResult results = HttpProcessor.acquire(new URL(url), outputStream); + if (!results.wasSuccessful()) { + throw new OseeCoreException("Error exporting osee types"); + } + } finally { + Lib.close(outputStream); + } + } + + private String getOseeFileName() { + return "OseeTypes_" + Lib.getDateTimeString() + ".osee"; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java index f1843f8d8f5..ba067d38b63 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/OseeTypesImportOperation.java @@ -1,141 +1,141 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.compare.CompareEditorInput; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; -import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput; -import org.eclipse.osee.framework.core.data.OseeServerContext; -import org.eclipse.osee.framework.core.dsl.integration.ModelUtil; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.enums.CoreTranslatorId; -import org.eclipse.osee.framework.core.message.OseeImportModelRequest; -import org.eclipse.osee.framework.core.message.OseeImportModelResponse; -import org.eclipse.osee.framework.core.message.TableData; -import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.plugin.core.util.Jobs; -import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.progress.UIJob; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesImportOperation extends AbstractOperation { - private final IOseeCachingService cacheService; - private final URI model; - private final boolean isPersistAllowed; - private final boolean createTypeChangeReport; - private final boolean createCompareReport; - - public OseeTypesImportOperation(IOseeCachingService cacheService, URI model, boolean createTypeChangeReport, boolean createCompareReport, boolean isPersistAllowed) { - super("Import Osee Types Model", Activator.PLUGIN_ID); - this.cacheService = cacheService; - this.model = model; - this.isPersistAllowed = isPersistAllowed; - this.createCompareReport = createCompareReport; - this.createTypeChangeReport = createTypeChangeReport; - } - - private String getModel(URL url) throws IOException { - InputStream inputStream = null; - try { - inputStream = new BufferedInputStream(url.openStream()); - return Lib.inputStreamToString(inputStream); - } finally { - Lib.close(inputStream); - } - } - - private String getName(URI uri) { - String name = uri.toASCIIString(); - int index = name.lastIndexOf("/"); - if (index > 0) { - name = name.substring(index + 1, name.length()); - } - return name; - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - Map parameters = new HashMap(); - - OseeImportModelRequest modelRequest = - new OseeImportModelRequest(getName(model), getModel(model.toURL()), createTypeChangeReport, - createCompareReport, isPersistAllowed); - - OseeImportModelResponse response = - HttpClientMessage.send(OseeServerContext.OSEE_MODEL_CONTEXT, parameters, - CoreTranslatorId.OSEE_IMPORT_MODEL_REQUEST, modelRequest, - CoreTranslatorId.OSEE_IMPORT_MODEL_RESPONSE); - - if (response.wasPersisted()) { - cacheService.getEnumTypeCache().reloadCache(); - cacheService.getAttributeTypeCache().reloadCache(); - cacheService.getArtifactTypeCache().reloadCache(); - cacheService.getRelationTypeCache().reloadCache(); - } - - if (createTypeChangeReport) { - openTabReport(response.getReportData()); - } - - if (createCompareReport) { - String compareName = response.getComparisonSnapshotModelName(); - String compareData = response.getComparisonSnapshotModel(); - if (Strings.isValid(compareData) && Strings.isValid(compareName)) { - ComparisonSnapshot snapshot = ModelUtil.loadComparisonSnapshot(compareName, compareData); - openCompareEditor(snapshot); - } - } - } - - private void openCompareEditor(final ComparisonSnapshot snapshot) { - Job job = new UIJob("Open Compare") { - - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - IStatus status; - try { - CompareEditorInput input = new ModelCompareEditorInput(snapshot); - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - page.openEditor(input, "org.eclipse.compare.CompareEditor", true); - status = Status.OK_STATUS; - } catch (Exception ex) { - status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error opening compare editor", ex); - } - return status; - } - }; - Jobs.startJob(job); - } - - private void openTabReport(List tableData) { - Operations.executeAsJob(new CreateEditorReportOperation("Un-Persisted Osee Types", tableData), true); - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.eclipse.compare.CompareEditorInput; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.compare.diff.metamodel.ComparisonSnapshot; +import org.eclipse.emf.compare.ui.editor.ModelCompareEditorInput; +import org.eclipse.osee.framework.core.data.OseeServerContext; +import org.eclipse.osee.framework.core.dsl.integration.ModelUtil; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.enums.CoreTranslatorId; +import org.eclipse.osee.framework.core.message.OseeImportModelRequest; +import org.eclipse.osee.framework.core.message.OseeImportModelResponse; +import org.eclipse.osee.framework.core.message.TableData; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.plugin.core.util.Jobs; +import org.eclipse.osee.framework.skynet.core.artifact.HttpClientMessage; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.UIJob; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesImportOperation extends AbstractOperation { + private final IOseeCachingService cacheService; + private final URI model; + private final boolean isPersistAllowed; + private final boolean createTypeChangeReport; + private final boolean createCompareReport; + + public OseeTypesImportOperation(IOseeCachingService cacheService, URI model, boolean createTypeChangeReport, boolean createCompareReport, boolean isPersistAllowed) { + super("Import Osee Types Model", Activator.PLUGIN_ID); + this.cacheService = cacheService; + this.model = model; + this.isPersistAllowed = isPersistAllowed; + this.createCompareReport = createCompareReport; + this.createTypeChangeReport = createTypeChangeReport; + } + + private String getModel(URL url) throws IOException { + InputStream inputStream = null; + try { + inputStream = new BufferedInputStream(url.openStream()); + return Lib.inputStreamToString(inputStream); + } finally { + Lib.close(inputStream); + } + } + + private String getName(URI uri) { + String name = uri.toASCIIString(); + int index = name.lastIndexOf("/"); + if (index > 0) { + name = name.substring(index + 1, name.length()); + } + return name; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + Map parameters = new HashMap(); + + OseeImportModelRequest modelRequest = + new OseeImportModelRequest(getName(model), getModel(model.toURL()), createTypeChangeReport, + createCompareReport, isPersistAllowed); + + OseeImportModelResponse response = + HttpClientMessage.send(OseeServerContext.OSEE_MODEL_CONTEXT, parameters, + CoreTranslatorId.OSEE_IMPORT_MODEL_REQUEST, modelRequest, + CoreTranslatorId.OSEE_IMPORT_MODEL_RESPONSE); + + if (response.wasPersisted()) { + cacheService.getEnumTypeCache().reloadCache(); + cacheService.getAttributeTypeCache().reloadCache(); + cacheService.getArtifactTypeCache().reloadCache(); + cacheService.getRelationTypeCache().reloadCache(); + } + + if (createTypeChangeReport) { + openTabReport(response.getReportData()); + } + + if (createCompareReport) { + String compareName = response.getComparisonSnapshotModelName(); + String compareData = response.getComparisonSnapshotModel(); + if (Strings.isValid(compareData) && Strings.isValid(compareName)) { + ComparisonSnapshot snapshot = ModelUtil.loadComparisonSnapshot(compareName, compareData); + openCompareEditor(snapshot); + } + } + } + + private void openCompareEditor(final ComparisonSnapshot snapshot) { + Job job = new UIJob("Open Compare") { + + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + IStatus status; + try { + CompareEditorInput input = new ModelCompareEditorInput(snapshot); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + page.openEditor(input, "org.eclipse.compare.CompareEditor", true); + status = Status.OK_STATUS; + } catch (Exception ex) { + status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error opening compare editor", ex); + } + return status; + } + }; + Jobs.startJob(job); + } + + private void openTabReport(List tableData) { + Operations.executeAsJob(new CreateEditorReportOperation("Un-Persisted Osee Types", tableData), true); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ResolveImportsOperation.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ResolveImportsOperation.java index a448e9a9461..0acc5e337bb 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ResolveImportsOperation.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/ResolveImportsOperation.java @@ -1,99 +1,99 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.common.util.URI; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.dsl.ui.integration.wizards.LinkMessage; -import org.eclipse.osee.framework.core.dsl.ui.integration.wizards.LinkNode; -import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.xtext.resource.IClasspathUriResolver; - -/** - * @author Roberto E. Escobar - */ -public class ResolveImportsOperation extends AbstractOperation { - private final Pattern pattern = Pattern.compile("\\s*import\\s+\"(.*?)\""); - private final List selectedItems; - private final Matcher matcher; - private final IClasspathUriResolver resolver; - private final List dependencyData; - - public ResolveImportsOperation(IClasspathUriResolver resolver, List selectedItems, List dependencyData) { - super("Extract imports", Activator.PLUGIN_ID); - this.matcher = pattern.matcher(""); - this.selectedItems = selectedItems; - this.resolver = resolver; - this.dependencyData = dependencyData; - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - if (!selectedItems.isEmpty()) { - double workPercentage = 1.0 / selectedItems.size(); - for (IFile selectedFile : selectedItems) { - URI uri = URI.createURI(selectedFile.getLocationURI().toASCIIString()); - LinkNode node = new LinkNode(uri); - dependencyData.add(node); - resolveImports(node); - } - monitor.worked(calculateWork(workPercentage)); - } - } - - private void resolveImports(LinkNode node) throws IOException { - if (node.getUri() != null) { - Set requiredImports = null; - try { - requiredImports = getImports(node.getUri()); - } catch (IOException ex) { - node.setIsResolved(false); - throw ex; - } - for (String importEntry : requiredImports) { - URI resolved = resolver.resolve((Object) null, URI.createURI(importEntry)); - LinkMessage message = new LinkMessage(resolved, importEntry); - node.addChild(message); - resolveImports(message); - } - } - } - - private Set getImports(URI uri) throws IOException { - Set imports = new HashSet(); - InputStream inputStream = null; - try { - inputStream = new BufferedInputStream(new URL(uri.toString()).openStream()); - String inputString = Lib.inputStreamToString(inputStream); - matcher.reset(inputString); - while (matcher.find()) { - imports.add(matcher.group(1)); - } - } finally { - if (inputStream != null) { - inputStream.close(); - } - } - return imports; - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.ui.integration.wizards.LinkMessage; +import org.eclipse.osee.framework.core.dsl.ui.integration.wizards.LinkNode; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.xtext.resource.IClasspathUriResolver; + +/** + * @author Roberto E. Escobar + */ +public class ResolveImportsOperation extends AbstractOperation { + private final Pattern pattern = Pattern.compile("\\s*import\\s+\"(.*?)\""); + private final List selectedItems; + private final Matcher matcher; + private final IClasspathUriResolver resolver; + private final List dependencyData; + + public ResolveImportsOperation(IClasspathUriResolver resolver, List selectedItems, List dependencyData) { + super("Extract imports", Activator.PLUGIN_ID); + this.matcher = pattern.matcher(""); + this.selectedItems = selectedItems; + this.resolver = resolver; + this.dependencyData = dependencyData; + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + if (!selectedItems.isEmpty()) { + double workPercentage = 1.0 / selectedItems.size(); + for (IFile selectedFile : selectedItems) { + URI uri = URI.createURI(selectedFile.getLocationURI().toASCIIString()); + LinkNode node = new LinkNode(uri); + dependencyData.add(node); + resolveImports(node); + } + monitor.worked(calculateWork(workPercentage)); + } + } + + private void resolveImports(LinkNode node) throws IOException { + if (node.getUri() != null) { + Set requiredImports = null; + try { + requiredImports = getImports(node.getUri()); + } catch (IOException ex) { + node.setIsResolved(false); + throw ex; + } + for (String importEntry : requiredImports) { + URI resolved = resolver.resolve((Object) null, URI.createURI(importEntry)); + LinkMessage message = new LinkMessage(resolved, importEntry); + node.addChild(message); + resolveImports(message); + } + } + } + + private Set getImports(URI uri) throws IOException { + Set imports = new HashSet(); + InputStream inputStream = null; + try { + inputStream = new BufferedInputStream(new URL(uri.toString()).openStream()); + String inputString = Lib.inputStreamToString(inputStream); + matcher.reset(inputString); + while (matcher.find()) { + imports.add(matcher.group(1)); + } + } finally { + if (inputStream != null) { + inputStream.close(); + } + } + return imports; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/XtextOseeTypesHandler.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/XtextOseeTypesHandler.java index 514c95cac1f..f3e9502c5dc 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/XtextOseeTypesHandler.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/operations/XtextOseeTypesHandler.java @@ -1,45 +1,45 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.operations; - -import java.net.URI; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.exception.OseeCoreException; -import org.eclipse.osee.framework.core.exception.OseeExceptions; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.skynet.core.importing.IOseeTypesHandler; - -/** - * @author Roberto E. Escobar - */ -public class XtextOseeTypesHandler implements IOseeTypesHandler { - - @Override - public void execute(IProgressMonitor monitor, URI uri) throws OseeCoreException { - try { - IOseeCachingService cacheService = Activator.getOseeCacheService(); - IOperation operation = new OseeTypesImportOperation(cacheService, uri, false, false, true); - Operations.executeWorkAndCheckStatus(operation, monitor, -1); - } catch (Exception ex) { - OseeExceptions.wrapAndThrow(ex); - } - } - - @Override - public boolean isApplicable(String resource) { - return Strings.isValid(resource) && resource.endsWith(".osee"); - } - -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.operations; + +import java.net.URI; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeExceptions; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.skynet.core.importing.IOseeTypesHandler; + +/** + * @author Roberto E. Escobar + */ +public class XtextOseeTypesHandler implements IOseeTypesHandler { + + @Override + public void execute(IProgressMonitor monitor, URI uri) throws OseeCoreException { + try { + IOseeCachingService cacheService = Activator.getOseeCacheService(); + IOperation operation = new OseeTypesImportOperation(cacheService, uri, false, false, true); + Operations.executeWorkAndCheckStatus(operation, monitor, -1); + } catch (Exception ex) { + OseeExceptions.wrapAndThrow(ex); + } + } + + @Override + public boolean isApplicable(String resource) { + return Strings.isValid(resource) && resource.endsWith(".osee"); + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkMessage.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkMessage.java index af6ea0bcff5..96762ddf28e 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkMessage.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkMessage.java @@ -1,29 +1,29 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import org.eclipse.emf.common.util.URI; - -/** - * @author Roberto E. Escobar - */ -public class LinkMessage extends LinkNode { - private final String importEntry; - - public LinkMessage(URI nodeURI, String importEntry) { - super(nodeURI); - this.importEntry = importEntry; - } - - public String getImportEntry() { - return importEntry; - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import org.eclipse.emf.common.util.URI; + +/** + * @author Roberto E. Escobar + */ +public class LinkMessage extends LinkNode { + private final String importEntry; + + public LinkMessage(URI nodeURI, String importEntry) { + super(nodeURI); + this.importEntry = importEntry; + } + + public String getImportEntry() { + return importEntry; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNode.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNode.java index 94f99a08bc5..9a1533914dd 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNode.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNode.java @@ -1,60 +1,60 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.emf.common.util.URI; - -/** - * @author Roberto E. Escobar - */ -public class LinkNode { - public LinkNode nodeParent; - public URI nodeURI; - public List children; - public boolean resolved; - - public LinkNode(URI nodeURI) { - this.nodeURI = nodeURI; - this.children = new ArrayList(); - this.resolved = true; - } - - public void addChild(LinkNode node) { - nodeParent = this; - children.add(node); - } - - public URI getUri() { - return nodeURI; - } - - public LinkNode getParent() { - return nodeParent; - } - - public boolean hasChildren() { - return !getChildren().isEmpty(); - } - - public List getChildren() { - return children; - } - - public void setIsResolved(boolean resolved) { - this.resolved = resolved; - } - - public boolean isResolved() { - return resolved; - } +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.emf.common.util.URI; + +/** + * @author Roberto E. Escobar + */ +public class LinkNode { + public LinkNode nodeParent; + public URI nodeURI; + public List children; + public boolean resolved; + + public LinkNode(URI nodeURI) { + this.nodeURI = nodeURI; + this.children = new ArrayList(); + this.resolved = true; + } + + public void addChild(LinkNode node) { + nodeParent = this; + children.add(node); + } + + public URI getUri() { + return nodeURI; + } + + public LinkNode getParent() { + return nodeParent; + } + + public boolean hasChildren() { + return !getChildren().isEmpty(); + } + + public List getChildren() { + return children; + } + + public void setIsResolved(boolean resolved) { + this.resolved = resolved; + } + + public boolean isResolved() { + return resolved; + } } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeContentProvider.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeContentProvider.java index 936a827d12a..86245d0d8ed 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeContentProvider.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeContentProvider.java @@ -1,60 +1,60 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.util.Collection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * @author Roberto E. Escobar - */ -public class LinkNodeContentProvider implements ITreeContentProvider { - - @Override - public Object[] getChildren(Object element) { - if (element instanceof LinkNode) { - return ((LinkNode) element).getChildren().toArray(); - } else if (element instanceof Collection) { - return ((Collection) element).toArray(); - } - return new Object[0]; - } - - @Override - public Object getParent(Object element) { - if (element instanceof LinkNode) { - return ((LinkNode) element).getParent(); - } - return null; - } - - @Override - public boolean hasChildren(Object element) { - if (element instanceof LinkNode) { - return ((LinkNode) element).hasChildren(); - } - return false; - } - - @Override - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.util.Collection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * @author Roberto E. Escobar + */ +public class LinkNodeContentProvider implements ITreeContentProvider { + + @Override + public Object[] getChildren(Object element) { + if (element instanceof LinkNode) { + return ((LinkNode) element).getChildren().toArray(); + } else if (element instanceof Collection) { + return ((Collection) element).toArray(); + } + return new Object[0]; + } + + @Override + public Object getParent(Object element) { + if (element instanceof LinkNode) { + return ((LinkNode) element).getParent(); + } + return null; + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof LinkNode) { + return ((LinkNode) element).hasChildren(); + } + return false; + } + + @Override + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeLabelProvider.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeLabelProvider.java index 59f0f59db35..f1a6b2f70c5 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeLabelProvider.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/LinkNodeLabelProvider.java @@ -1,53 +1,53 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.osee.framework.ui.skynet.FrameworkImage; -import org.eclipse.osee.framework.ui.swt.ImageManager; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -/** - * @author Roberto E. Escobar - */ -public class LinkNodeLabelProvider extends LabelProvider { - - @Override - public Image getImage(Object element) { - Image toReturn = super.getImage(element); - LinkNode node = null; - if (element instanceof LinkNode) { - node = (LinkNode) element; - toReturn = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); - } - if (element instanceof LinkMessage) { - toReturn = ImageManager.getImage(FrameworkImage.OSEE_TYPES_LINK); - } - if (node != null && !node.isResolved()) { - toReturn = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); - } - return toReturn; - } - - @Override - public String getText(Object element) { - if (element instanceof LinkMessage) { - return ((LinkMessage) element).getImportEntry(); - } else if (element instanceof LinkNode) { - LinkNode node = (LinkNode) element; - return node.getUri().toFileString(); - } - return super.getText(element); - } - -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.osee.framework.ui.skynet.FrameworkImage; +import org.eclipse.osee.framework.ui.swt.ImageManager; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * @author Roberto E. Escobar + */ +public class LinkNodeLabelProvider extends LabelProvider { + + @Override + public Image getImage(Object element) { + Image toReturn = super.getImage(element); + LinkNode node = null; + if (element instanceof LinkNode) { + node = (LinkNode) element; + toReturn = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); + } + if (element instanceof LinkMessage) { + toReturn = ImageManager.getImage(FrameworkImage.OSEE_TYPES_LINK); + } + if (node != null && !node.isResolved()) { + toReturn = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK); + } + return toReturn; + } + + @Override + public String getText(Object element) { + if (element instanceof LinkMessage) { + return ((LinkMessage) element).getImportEntry(); + } else if (element instanceof LinkNode) { + LinkNode node = (LinkNode) element; + return node.getUri().toFileString(); + } + return super.getText(element); + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesExportWizard.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesExportWizard.java index 8ec6ec9f600..77c152c1a52 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesExportWizard.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesExportWizard.java @@ -1,59 +1,59 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.dsl.ui.integration.operations.OseeTypesExportOperation; -import org.eclipse.osee.framework.core.operation.CompositeOperation; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesExportWizard extends Wizard implements IImportWizard { - private ResourceSelectionPage mainPage; - - public OseeTypesExportWizard() { - super(); - // setDialogSettings(Activator.getInstance().getDialogSettings()); - setWindowTitle("OSEE Types Export Wizard"); - setNeedsProgressMonitor(true); - setHelpAvailable(true); - } - - @Override - public boolean performFinish() { - final File folder = mainPage.getFile(); - - List ops = new ArrayList(); - ops.add(new OseeTypesExportOperation(folder)); - Operations.executeAsJob(new CompositeOperation("Export Osee Type Model", Activator.PLUGIN_ID, ops), true); - return true; - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - mainPage = new ResourceSelectionPage(getWindowTitle()); - } - - @Override - public void addPages() { - addPage(mainPage); - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.ui.integration.operations.OseeTypesExportOperation; +import org.eclipse.osee.framework.core.operation.CompositeOperation; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesExportWizard extends Wizard implements IImportWizard { + private ResourceSelectionPage mainPage; + + public OseeTypesExportWizard() { + super(); + // setDialogSettings(Activator.getInstance().getDialogSettings()); + setWindowTitle("OSEE Types Export Wizard"); + setNeedsProgressMonitor(true); + setHelpAvailable(true); + } + + @Override + public boolean performFinish() { + final File folder = mainPage.getFile(); + + List ops = new ArrayList(); + ops.add(new OseeTypesExportOperation(folder)); + Operations.executeAsJob(new CompositeOperation("Export Osee Type Model", Activator.PLUGIN_ID, ops), true); + return true; + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + mainPage = new ResourceSelectionPage(getWindowTitle()); + } + + @Override + public void addPages() { + addPage(mainPage); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportPage.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportPage.java index 723f6c6d96e..7257dff1800 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportPage.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportPage.java @@ -1,262 +1,262 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.io.File; -import java.lang.reflect.InvocationTargetException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.dsl.ui.integration.operations.ResolveImportsOperation; -import org.eclipse.osee.framework.core.operation.AbstractOperation; -import org.eclipse.osee.framework.core.operation.CompositeOperation; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.database.init.OseeTypesSetup; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.dialogs.WizardDataTransferPage; -import org.eclipse.xtext.resource.ClassloaderClasspathUriResolver; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesImportPage extends WizardDataTransferPage { - private static final String PAGE_NAME = - "org.eclipse.osee.framework.core.dsl.ui.integration.wizards.OseeTypesImportPage"; - - private final OseeTypesSetup oseeTypesSetup; - private File compositeFile; - private final IStructuredSelection selection; - private TreeViewer linksViewer; - private final SelectOseeTypesPanel oseeTypesPanel; - private final List messages; - private Button reportChanges; - private Button persistChanges; - private Button useCompareEditor; - - protected OseeTypesImportPage(IStructuredSelection selection, String title) { - super(PAGE_NAME); - this.selection = selection; - oseeTypesSetup = new OseeTypesSetup(); - oseeTypesPanel = new SelectOseeTypesPanel(); - oseeTypesPanel.setDefaultItem(getPreselected()); - setTitle(title); - setDescription("Select *.osee files to import"); - messages = new ArrayList(); - } - - private List getPreselected() { - List resources = new ArrayList(); - if (selection != null) { - Iterator iterator = selection.iterator(); - while (iterator.hasNext()) { - Object object = iterator.next(); - if (object instanceof IFile) { - IFile file = (IFile) object; - if (file.getFileExtension().equals("osee")) { - resources.add(file); - } - } - } - } - return resources; - } - - @Override - protected boolean allowNewContainerName() { - return false; - } - - @Override - public void handleEvent(Event event) { - updateWidgetEnablements(); - updateExtractedElements(); - } - - @Override - public void createControl(Composite parent) { - initializeDialogUnits(parent); - - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout(1, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - composite.setFont(parent.getFont()); - - oseeTypesPanel.createControl(composite); - oseeTypesPanel.addListener(this); - - Label sectionTitle = new Label(composite, SWT.NONE); - sectionTitle.setText("Resolved dependencies:"); - sectionTitle.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false)); - - linksViewer = new TreeViewer(composite, SWT.BORDER); - linksViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - linksViewer.setContentProvider(new LinkNodeContentProvider()); - linksViewer.setLabelProvider(new LinkNodeLabelProvider()); - linksViewer.setInput(messages); - - createOptions(composite); - - restoreWidgetValues(); - updateWidgetEnablements(); - updateExtractedElements(); - setPageComplete(determinePageCompletion()); - setControl(composite); - } - - private void createOptions(Composite parent) { - Group composite = new Group(parent, SWT.NULL); - composite.setLayout(new GridLayout(1, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - composite.setFont(parent.getFont()); - composite.setText("Options"); - - reportChanges = new Button(composite, SWT.CHECK); - reportChanges.setText("Report Changes"); - reportChanges.setSelection(true); - - useCompareEditor = new Button(composite, SWT.CHECK); - useCompareEditor.setText("Use Compare Editor"); - useCompareEditor.setSelection(false); - - persistChanges = new Button(composite, SWT.CHECK); - persistChanges.setText("Persist Changes"); - persistChanges.setSelection(false); - } - - public boolean isPersistAllowed() { - return persistChanges.getSelection(); - } - - public boolean isReportChanges() { - return reportChanges.getSelection(); - } - - public boolean useCompareEditor() { - return useCompareEditor.getSelection(); - } - - public File getTypesToImport() { - return compositeFile != null ? compositeFile : null; - } - - private void setCompositeFile(File compositeFile) { - this.compositeFile = compositeFile; - } - - @Override - protected boolean validateSourceGroup() { - return oseeTypesPanel.getSelected() != null; - } - - @Override - protected boolean validateDestinationGroup() { - return getTypesToImport() != null; - } - - private synchronized void updateExtractedElements() { - if (oseeTypesPanel.getSelected() != null) { - setErrorMessage(null); - File file = getTypesToImport(); - if (file != null) { - file.delete(); - setCompositeFile(null); - } - OseeLog.log(Activator.class, Level.INFO, "Resolving imports"); - - final List selectedFiles = new ArrayList(oseeTypesPanel.getSelected()); - final List dependencyData = new ArrayList(); - - Collection ops = new ArrayList(); - ops.add(new ResolveImportsOperation(new ClassloaderClasspathUriResolver(), selectedFiles, dependencyData)); - ops.add(new CreateCombinedFile(dependencyData)); - if (executeOperation(new CompositeOperation("Resolving imports", Activator.PLUGIN_ID, ops))) { - messages.clear(); - messages.addAll(dependencyData); - linksViewer.refresh(); - setPageComplete(determinePageCompletion()); - } - } - } - - protected boolean executeOperation(final IOperation operation) { - try { - getContainer().run(true, true, new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) { - Operations.executeWork(operation, monitor, -1); - } - }); - } catch (InterruptedException e) { - return false; - } catch (InvocationTargetException e) { - displayErrorDialog(e.getTargetException()); - return false; - } - - IStatus status = operation.getStatus(); - if (status.isOK()) { - setErrorMessage(null); - } else { - setErrorMessage(status.getChildren()[0].getMessage()); - } - return true; - } - - private final class CreateCombinedFile extends AbstractOperation { - private final List dependencyData; - - public CreateCombinedFile(List dependencyData) { - super("Create combined file", Activator.PLUGIN_ID); - this.dependencyData = dependencyData; - } - - private void loadMap(LinkNode node, Map map) throws MalformedURLException { - for (LinkNode child : node.getChildren()) { - loadMap(child, map); - } - String path = node.getUri().toString(); - map.put(path, new URL(node.getUri().toString())); - } - - @Override - protected void doWork(IProgressMonitor monitor) throws Exception { - Map resolvedEntries = new LinkedHashMap(); - for (LinkNode node : dependencyData) { - loadMap(node, resolvedEntries); - } - File file = oseeTypesSetup.createCombinedFile(resolvedEntries); - setCompositeFile(file); - } - } +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.ui.integration.operations.ResolveImportsOperation; +import org.eclipse.osee.framework.core.operation.AbstractOperation; +import org.eclipse.osee.framework.core.operation.CompositeOperation; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.database.init.OseeTypesSetup; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.dialogs.WizardDataTransferPage; +import org.eclipse.xtext.resource.ClassloaderClasspathUriResolver; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesImportPage extends WizardDataTransferPage { + private static final String PAGE_NAME = + "org.eclipse.osee.framework.core.dsl.ui.integration.wizards.OseeTypesImportPage"; + + private final OseeTypesSetup oseeTypesSetup; + private File compositeFile; + private final IStructuredSelection selection; + private TreeViewer linksViewer; + private final SelectOseeTypesPanel oseeTypesPanel; + private final List messages; + private Button reportChanges; + private Button persistChanges; + private Button useCompareEditor; + + protected OseeTypesImportPage(IStructuredSelection selection, String title) { + super(PAGE_NAME); + this.selection = selection; + oseeTypesSetup = new OseeTypesSetup(); + oseeTypesPanel = new SelectOseeTypesPanel(); + oseeTypesPanel.setDefaultItem(getPreselected()); + setTitle(title); + setDescription("Select *.osee files to import"); + messages = new ArrayList(); + } + + private List getPreselected() { + List resources = new ArrayList(); + if (selection != null) { + Iterator iterator = selection.iterator(); + while (iterator.hasNext()) { + Object object = iterator.next(); + if (object instanceof IFile) { + IFile file = (IFile) object; + if (file.getFileExtension().equals("osee")) { + resources.add(file); + } + } + } + } + return resources; + } + + @Override + protected boolean allowNewContainerName() { + return false; + } + + @Override + public void handleEvent(Event event) { + updateWidgetEnablements(); + updateExtractedElements(); + } + + @Override + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout(1, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setFont(parent.getFont()); + + oseeTypesPanel.createControl(composite); + oseeTypesPanel.addListener(this); + + Label sectionTitle = new Label(composite, SWT.NONE); + sectionTitle.setText("Resolved dependencies:"); + sectionTitle.setLayoutData(new GridData(SWT.BEGINNING, SWT.TOP, true, false)); + + linksViewer = new TreeViewer(composite, SWT.BORDER); + linksViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + linksViewer.setContentProvider(new LinkNodeContentProvider()); + linksViewer.setLabelProvider(new LinkNodeLabelProvider()); + linksViewer.setInput(messages); + + createOptions(composite); + + restoreWidgetValues(); + updateWidgetEnablements(); + updateExtractedElements(); + setPageComplete(determinePageCompletion()); + setControl(composite); + } + + private void createOptions(Composite parent) { + Group composite = new Group(parent, SWT.NULL); + composite.setLayout(new GridLayout(1, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setFont(parent.getFont()); + composite.setText("Options"); + + reportChanges = new Button(composite, SWT.CHECK); + reportChanges.setText("Report Changes"); + reportChanges.setSelection(true); + + useCompareEditor = new Button(composite, SWT.CHECK); + useCompareEditor.setText("Use Compare Editor"); + useCompareEditor.setSelection(false); + + persistChanges = new Button(composite, SWT.CHECK); + persistChanges.setText("Persist Changes"); + persistChanges.setSelection(false); + } + + public boolean isPersistAllowed() { + return persistChanges.getSelection(); + } + + public boolean isReportChanges() { + return reportChanges.getSelection(); + } + + public boolean useCompareEditor() { + return useCompareEditor.getSelection(); + } + + public File getTypesToImport() { + return compositeFile != null ? compositeFile : null; + } + + private void setCompositeFile(File compositeFile) { + this.compositeFile = compositeFile; + } + + @Override + protected boolean validateSourceGroup() { + return oseeTypesPanel.getSelected() != null; + } + + @Override + protected boolean validateDestinationGroup() { + return getTypesToImport() != null; + } + + private synchronized void updateExtractedElements() { + if (oseeTypesPanel.getSelected() != null) { + setErrorMessage(null); + File file = getTypesToImport(); + if (file != null) { + file.delete(); + setCompositeFile(null); + } + OseeLog.log(Activator.class, Level.INFO, "Resolving imports"); + + final List selectedFiles = new ArrayList(oseeTypesPanel.getSelected()); + final List dependencyData = new ArrayList(); + + Collection ops = new ArrayList(); + ops.add(new ResolveImportsOperation(new ClassloaderClasspathUriResolver(), selectedFiles, dependencyData)); + ops.add(new CreateCombinedFile(dependencyData)); + if (executeOperation(new CompositeOperation("Resolving imports", Activator.PLUGIN_ID, ops))) { + messages.clear(); + messages.addAll(dependencyData); + linksViewer.refresh(); + setPageComplete(determinePageCompletion()); + } + } + } + + protected boolean executeOperation(final IOperation operation) { + try { + getContainer().run(true, true, new IRunnableWithProgress() { + + @Override + public void run(IProgressMonitor monitor) { + Operations.executeWork(operation, monitor, -1); + } + }); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + displayErrorDialog(e.getTargetException()); + return false; + } + + IStatus status = operation.getStatus(); + if (status.isOK()) { + setErrorMessage(null); + } else { + setErrorMessage(status.getChildren()[0].getMessage()); + } + return true; + } + + private final class CreateCombinedFile extends AbstractOperation { + private final List dependencyData; + + public CreateCombinedFile(List dependencyData) { + super("Create combined file", Activator.PLUGIN_ID); + this.dependencyData = dependencyData; + } + + private void loadMap(LinkNode node, Map map) throws MalformedURLException { + for (LinkNode child : node.getChildren()) { + loadMap(child, map); + } + String path = node.getUri().toString(); + map.put(path, new URL(node.getUri().toString())); + } + + @Override + protected void doWork(IProgressMonitor monitor) throws Exception { + Map resolvedEntries = new LinkedHashMap(); + for (LinkNode node : dependencyData) { + loadMap(node, resolvedEntries); + } + File file = oseeTypesSetup.createCombinedFile(resolvedEntries); + setCompositeFile(file); + } + } } \ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportWizard.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportWizard.java index 24ea6788c1e..652de0ddfd3 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportWizard.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesImportWizard.java @@ -1,71 +1,71 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.io.File; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.core.dsl.ui.integration.operations.OseeTypesImportOperation; -import org.eclipse.osee.framework.core.operation.IOperation; -import org.eclipse.osee.framework.core.operation.Operations; -import org.eclipse.osee.framework.core.services.IOseeCachingService; -import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesImportWizard extends Wizard implements IImportWizard { - private OseeTypesImportPage mainPage; - - public OseeTypesImportWizard() { - super(); - setDialogSettings(SkynetGuiPlugin.getInstance().getDialogSettings()); - setWindowTitle("OSEE Types Import Wizard"); - setNeedsProgressMonitor(true); - setHelpAvailable(true); - } - - @Override - public boolean performFinish() { - final File file = mainPage.getTypesToImport(); - boolean isReport = mainPage.isReportChanges(); - boolean useCompareEditor = mainPage.useCompareEditor(); - boolean isPersistAllowed = mainPage.isPersistAllowed(); - - IOseeCachingService cacheService = Activator.getOseeCacheService(); - IOperation operation = - new OseeTypesImportOperation(cacheService, file.toURI(), isReport, useCompareEditor, isPersistAllowed); - Job job = Operations.executeAsJob(operation, true); - job.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(IJobChangeEvent event) { - file.delete(); - } - }); - return true; - } - - @Override - public void init(IWorkbench workbench, IStructuredSelection selection) { - mainPage = new OseeTypesImportPage(selection, getWindowTitle()); - } - - @Override - public void addPages() { - addPage(mainPage); - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.io.File; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.core.dsl.ui.integration.operations.OseeTypesImportOperation; +import org.eclipse.osee.framework.core.operation.IOperation; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.core.services.IOseeCachingService; +import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesImportWizard extends Wizard implements IImportWizard { + private OseeTypesImportPage mainPage; + + public OseeTypesImportWizard() { + super(); + setDialogSettings(SkynetGuiPlugin.getInstance().getDialogSettings()); + setWindowTitle("OSEE Types Import Wizard"); + setNeedsProgressMonitor(true); + setHelpAvailable(true); + } + + @Override + public boolean performFinish() { + final File file = mainPage.getTypesToImport(); + boolean isReport = mainPage.isReportChanges(); + boolean useCompareEditor = mainPage.useCompareEditor(); + boolean isPersistAllowed = mainPage.isPersistAllowed(); + + IOseeCachingService cacheService = Activator.getOseeCacheService(); + IOperation operation = + new OseeTypesImportOperation(cacheService, file.toURI(), isReport, useCompareEditor, isPersistAllowed); + Job job = Operations.executeAsJob(operation, true); + job.addJobChangeListener(new JobChangeAdapter() { + @Override + public void done(IJobChangeEvent event) { + file.delete(); + } + }); + return true; + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + mainPage = new OseeTypesImportPage(selection, getWindowTitle()); + } + + @Override + public void addPages() { + addPage(mainPage); + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesViewerFilter.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesViewerFilter.java index ac91f169bcb..cf7d491af03 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesViewerFilter.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/OseeTypesViewerFilter.java @@ -1,73 +1,73 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.util.logging.Level; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.jdk.core.type.MutableBoolean; -import org.eclipse.osee.framework.logging.OseeLog; - -/** - * @author Roberto E. Escobar - */ -public class OseeTypesViewerFilter extends ViewerFilter { - - private boolean processIFile(Object resource) { - boolean toReturn = false; - if (resource instanceof IFile) { - IFile aFile = (IFile) resource; - String currentExtension = aFile.getFileExtension(); - if (currentExtension.equalsIgnoreCase("osee")) { - toReturn = true; - } - } - return toReturn; - } - - @Override - public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof IProject) { - if (((IProject) element).isOpen()) { - return true; - } - } else if (element instanceof IContainer) { - IContainer container = (IContainer) element; - String name = container.getName(); - if (!name.startsWith(".") && !name.equals("osee")) { - final MutableBoolean mutable = new MutableBoolean(false); - try { - container.accept(new IResourceVisitor() { - - @Override - public boolean visit(IResource resource) { - mutable.setValue(processIFile(resource)); - return mutable.getValue(); - } - }, IResource.DEPTH_INFINITE, true); - } catch (CoreException ex) { - OseeLog.log(Activator.class, Level.SEVERE, ex); - } - return mutable.getValue(); - } - } else { - return processIFile(element); - } - return false; - } -} +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.util.logging.Level; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceVisitor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.jdk.core.type.MutableBoolean; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Roberto E. Escobar + */ +public class OseeTypesViewerFilter extends ViewerFilter { + + private boolean processIFile(Object resource) { + boolean toReturn = false; + if (resource instanceof IFile) { + IFile aFile = (IFile) resource; + String currentExtension = aFile.getFileExtension(); + if (currentExtension.equalsIgnoreCase("osee")) { + toReturn = true; + } + } + return toReturn; + } + + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + if (element instanceof IProject) { + if (((IProject) element).isOpen()) { + return true; + } + } else if (element instanceof IContainer) { + IContainer container = (IContainer) element; + String name = container.getName(); + if (!name.startsWith(".") && !name.equals("osee")) { + final MutableBoolean mutable = new MutableBoolean(false); + try { + container.accept(new IResourceVisitor() { + + @Override + public boolean visit(IResource resource) { + mutable.setValue(processIFile(resource)); + return mutable.getValue(); + } + }, IResource.DEPTH_INFINITE, true); + } catch (CoreException ex) { + OseeLog.log(Activator.class, Level.SEVERE, ex); + } + return mutable.getValue(); + } + } else { + return processIFile(element); + } + return false; + } +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/ResourceSelectionPage.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/ResourceSelectionPage.java index e4816ba0092..94e7a955c77 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/ResourceSelectionPage.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/ResourceSelectionPage.java @@ -8,91 +8,91 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.io.File; - -import org.eclipse.osee.framework.jdk.core.util.Strings; -import org.eclipse.osee.framework.ui.ws.AWorkspace; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.dialogs.WizardDataTransferPage; - -public class ResourceSelectionPage extends WizardDataTransferPage { - private static final String PAGE_NAME = "osee.define.wizardPage.artifactImportSourcePage"; - - private Text text; - - protected ResourceSelectionPage(String title) { - super(PAGE_NAME); - setTitle(title); - setDescription(title); - } - - @Override - protected boolean allowNewContainerName() { - return false; - } - - @Override - public void handleEvent(Event event) { - updateWidgetEnablements(); - setPageComplete(determinePageCompletion()); - } - - @Override - public void createControl(Composite parent) { - initializeDialogUnits(parent); - - Group composite = new Group(parent, SWT.NONE); - composite.setText("Select destination..."); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - composite.setFont(parent.getFont()); - - text = new Text(composite, SWT.SINGLE | SWT.BORDER); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - text.addListener(SWT.Modify, this); - - Button button = new Button(composite, SWT.PUSH); - button.setText("&Browse..."); - button.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN); - File file = getFile(); - if (file != null && Strings.isValid(file.getAbsolutePath())) { - dialog.setFilterPath(file.getAbsolutePath()); - } else { - dialog.setFilterPath(AWorkspace.getWorkspacePath()); - } - String path = dialog.open(); - - File directory = path != null ? new File(path) : null; - if (directory != null && directory.isDirectory()) { - text.setText(directory.getPath()); - } - } - }); - - restoreWidgetValues(); - updateWidgetEnablements(); - setPageComplete(determinePageCompletion()); - setControl(composite); - } - - public File getFile() { - return new File(text.getText()); - } - -} +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.io.File; + +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.ui.ws.AWorkspace; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.WizardDataTransferPage; + +public class ResourceSelectionPage extends WizardDataTransferPage { + private static final String PAGE_NAME = "osee.define.wizardPage.artifactImportSourcePage"; + + private Text text; + + protected ResourceSelectionPage(String title) { + super(PAGE_NAME); + setTitle(title); + setDescription(title); + } + + @Override + protected boolean allowNewContainerName() { + return false; + } + + @Override + public void handleEvent(Event event) { + updateWidgetEnablements(); + setPageComplete(determinePageCompletion()); + } + + @Override + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + Group composite = new Group(parent, SWT.NONE); + composite.setText("Select destination..."); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + composite.setFont(parent.getFont()); + + text = new Text(composite, SWT.SINGLE | SWT.BORDER); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + text.addListener(SWT.Modify, this); + + Button button = new Button(composite, SWT.PUSH); + button.setText("&Browse..."); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN); + File file = getFile(); + if (file != null && Strings.isValid(file.getAbsolutePath())) { + dialog.setFilterPath(file.getAbsolutePath()); + } else { + dialog.setFilterPath(AWorkspace.getWorkspacePath()); + } + String path = dialog.open(); + + File directory = path != null ? new File(path) : null; + if (directory != null && directory.isDirectory()) { + text.setText(directory.getPath()); + } + } + }); + + restoreWidgetValues(); + updateWidgetEnablements(); + setPageComplete(determinePageCompletion()); + setControl(composite); + } + + public File getFile() { + return new File(text.getText()); + } + +} diff --git a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/SelectOseeTypesPanel.java b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/SelectOseeTypesPanel.java index 57c2eb4f464..1525e12f0e9 100644 --- a/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/SelectOseeTypesPanel.java +++ b/plugins/org.eclipse.osee.framework.core.dsl.ui.integration/src/org/eclipse/osee/framework/core/dsl/ui/integration/wizards/SelectOseeTypesPanel.java @@ -1,92 +1,92 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; - -import java.util.ArrayList; -import java.util.List; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; -import org.eclipse.osee.framework.ui.skynet.panels.AbstractItemSelectPanel; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; - -/** - * @author Roberto E. Escobar - */ -public class SelectOseeTypesPanel extends AbstractItemSelectPanel> { - - public SelectOseeTypesPanel() { - super(new WorkbenchLabelProvider(), new ArrayContentProvider()); - } - - @Override - protected Dialog createSelectDialog(Shell shell, List lastSelected) { - CheckedTreeSelectionDialog dialog = - new CheckedTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); - dialog.addFilter(new OseeTypesViewerFilter()); - dialog.setTitle("Select OseeTypes to import"); - dialog.setValidator(new Validator()); - dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); - if (lastSelected != null) { - dialog.setInitialElementSelections(lastSelected); - } - return dialog; - } - - @Override - protected boolean updateFromDialogResult(Dialog dialog) { - boolean updateRequired = false; - if (dialog instanceof CheckedTreeSelectionDialog) { - Object[] results = ((CheckedTreeSelectionDialog) dialog).getResult(); - if (results != null && results.length > 0) { - List selected = new ArrayList(); - for (Object object : results) { - if (object instanceof IFile) { - selected.add((IFile) object); - } - } - if (!selected.isEmpty()) { - setSelected(selected); - updateRequired = true; - } - } - } - return updateRequired; - } - - private final class Validator implements ISelectionStatusValidator { - @Override - public IStatus validate(Object[] selection) { - IStatus status = Status.OK_STATUS; - boolean found = false; - if (selection != null) { - for (Object object : selection) { - if (object instanceof IFile) { - found = true; - break; - } - } - } - if (!found) { - status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "At least (1) must be selected"); - } - return status; - } - } +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.dsl.ui.integration.wizards; + +import java.util.ArrayList; +import java.util.List; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.osee.framework.core.dsl.ui.integration.internal.Activator; +import org.eclipse.osee.framework.ui.skynet.panels.AbstractItemSelectPanel; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +/** + * @author Roberto E. Escobar + */ +public class SelectOseeTypesPanel extends AbstractItemSelectPanel> { + + public SelectOseeTypesPanel() { + super(new WorkbenchLabelProvider(), new ArrayContentProvider()); + } + + @Override + protected Dialog createSelectDialog(Shell shell, List lastSelected) { + CheckedTreeSelectionDialog dialog = + new CheckedTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); + dialog.addFilter(new OseeTypesViewerFilter()); + dialog.setTitle("Select OseeTypes to import"); + dialog.setValidator(new Validator()); + dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); + if (lastSelected != null) { + dialog.setInitialElementSelections(lastSelected); + } + return dialog; + } + + @Override + protected boolean updateFromDialogResult(Dialog dialog) { + boolean updateRequired = false; + if (dialog instanceof CheckedTreeSelectionDialog) { + Object[] results = ((CheckedTreeSelectionDialog) dialog).getResult(); + if (results != null && results.length > 0) { + List selected = new ArrayList(); + for (Object object : results) { + if (object instanceof IFile) { + selected.add((IFile) object); + } + } + if (!selected.isEmpty()) { + setSelected(selected); + updateRequired = true; + } + } + } + return updateRequired; + } + + private final class Validator implements ISelectionStatusValidator { + @Override + public IStatus validate(Object[] selection) { + IStatus status = Status.OK_STATUS; + boolean found = false; + if (selection != null) { + for (Object object : selection) { + if (object instanceof IFile) { + found = true; + break; + } + } + } + if (!found) { + status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "At least (1) must be selected"); + } + return status; + } + } } \ No newline at end of file -- cgit v1.2.3