| /* |
| * Copyright (c) 2006, 2007 Borland Software Corporation |
| * |
| * 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: |
| * Dmitry Stadnik (Borland) - initial API and implementation |
| */ |
| package org.eclipse.gmf.examples.taipan.gmf.editor.parsers; |
| |
| import org.eclipse.core.runtime.IAdaptable; |
| import org.eclipse.emf.ecore.EAttribute; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.gmf.runtime.common.core.command.ICommand; |
| import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand; |
| import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus; |
| import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus; |
| import org.eclipse.gmf.tooling.runtime.parsers.AbstractAttributeParser; |
| |
| /** |
| * @generated |
| */ |
| public class PrintfRegexpParser extends AbstractAttributeParser { |
| |
| /** |
| * @generated |
| */ |
| private String defaultPattern; |
| |
| /** |
| * @generated |
| */ |
| private String defaultEditablePattern; |
| |
| /** |
| * @generated |
| */ |
| public PrintfRegexpParser(EAttribute[] features) { |
| super(features); |
| } |
| |
| /** |
| * @generated |
| */ |
| public PrintfRegexpParser(EAttribute[] features, EAttribute[] editableFeatures) { |
| super(features, editableFeatures); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected String getDefaultPattern() { |
| if (defaultPattern == null) { |
| StringBuffer sb = new StringBuffer(); |
| for (int i = 0; i < features.length; i++) { |
| if (i > 0) { |
| sb.append(' '); |
| } |
| sb.append('%'); |
| sb.append(i + 1); |
| sb.append('$'); |
| sb.append('s'); |
| } |
| defaultPattern = sb.toString(); |
| } |
| return defaultPattern; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected String getDefaultEditablePattern() { |
| if (defaultEditablePattern == null) { |
| StringBuffer sb = new StringBuffer(); |
| for (int i = 0; i < editableFeatures.length; i++) { |
| if (i > 0) { |
| sb.append(' '); |
| } |
| sb.append('%'); |
| sb.append(i + 1); |
| sb.append('$'); |
| sb.append('s'); |
| } |
| defaultEditablePattern = sb.toString(); |
| } |
| return defaultEditablePattern; |
| } |
| |
| /** |
| * @generated |
| */ |
| public String getEditPattern() { |
| String pattern = super.getEditPattern(); |
| return pattern != null ? pattern : " "; //$NON-NLS-1$ |
| } |
| |
| /** |
| * @generated |
| */ |
| public String getEditString(IAdaptable adapter, int flags) { |
| EObject element = (EObject) adapter.getAdapter(EObject.class); |
| String pattern = getEditorPattern() == null ? getDefaultEditablePattern() : getEditorPattern(); |
| return String.format(pattern, getEditableValues(element)); |
| } |
| |
| /** |
| * @generated |
| */ |
| public IParserEditStatus isValidEditString(IAdaptable adapter, String editString) { |
| if (editString == null) { |
| return ParserEditStatus.UNEDITABLE_STATUS; |
| } |
| Object[] values = editString.split(getEditPattern()); |
| return validateNewValues(values); |
| } |
| |
| /** |
| * @generated |
| */ |
| public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) { |
| if (newString == null) { |
| return UnexecutableCommand.INSTANCE; |
| } |
| Object[] values = newString.split(getEditPattern()); |
| return super.getParseCommand(adapter, values, flags); |
| } |
| |
| /** |
| * @generated |
| */ |
| public String getPrintString(IAdaptable adapter, int flags) { |
| EObject element = (EObject) adapter.getAdapter(EObject.class); |
| return String.format(getViewPattern() == null ? getDefaultPattern() : getViewPattern(), getValues(element)); |
| } |
| |
| } |